Skip to main content
added link to search parameter in Craft documentation.
Source Link

The search parametersearch parameter will help you do this really elegantly.

In the code below I've called the category field categoryField, but you'll have to swap that to suit your site.

{# Get current students (students who aren't also in the alumni category) #}
{% set currentStudents = craft.entries.section('people').search('categoryField:student -categoryField:alumni') %}

{% for student in currentStudents %}
    {# Output your students here #}
{% endfor %}

This is basically asking Craft to respond with the entries that have the categoryField including student but not (indicated by the - before) including alumni.

You could probably also streamline the other bits of your code using this method.

I've tested this as working on Craft 2.5.2757

Hope that helps!

The search parameter will help you do this really elegantly.

In the code below I've called the category field categoryField, but you'll have to swap that to suit your site.

{# Get current students (students who aren't also in the alumni category) #}
{% set currentStudents = craft.entries.section('people').search('categoryField:student -categoryField:alumni') %}

{% for student in currentStudents %}
    {# Output your students here #}
{% endfor %}

This is basically asking Craft to respond with the entries that have the categoryField including student but not (indicated by the - before) including alumni.

You could probably also streamline the other bits of your code using this method.

I've tested this as working on Craft 2.5.2757

Hope that helps!

The search parameter will help you do this really elegantly.

In the code below I've called the category field categoryField, but you'll have to swap that to suit your site.

{# Get current students (students who aren't also in the alumni category) #}
{% set currentStudents = craft.entries.section('people').search('categoryField:student -categoryField:alumni') %}

{% for student in currentStudents %}
    {# Output your students here #}
{% endfor %}

This is basically asking Craft to respond with the entries that have the categoryField including student but not (indicated by the - before) including alumni.

You could probably also streamline the other bits of your code using this method.

I've tested this as working on Craft 2.5.2757

Hope that helps!

Source Link
Mutual
  • 442
  • 2
  • 11

The search parameter will help you do this really elegantly.

In the code below I've called the category field categoryField, but you'll have to swap that to suit your site.

{# Get current students (students who aren't also in the alumni category) #}
{% set currentStudents = craft.entries.section('people').search('categoryField:student -categoryField:alumni') %}

{% for student in currentStudents %}
    {# Output your students here #}
{% endfor %}

This is basically asking Craft to respond with the entries that have the categoryField including student but not (indicated by the - before) including alumni.

You could probably also streamline the other bits of your code using this method.

I've tested this as working on Craft 2.5.2757

Hope that helps!