1. cliveportman
  2. /code
  3. /fetching-multiple-entry-types-or-excluding-entry-types-from-craft-entries-within-craft-cms

Fetching multiple entry types or excluding entry types from craft.entries within Craft CMS

Using a structure with multiple entry types I need to fetch different entry types depending on the context. Fetching children of only one type is no problem:

{% set cats = entry.children().type('category') %}

But I then want to fetch children which don't belong to that category. Either of these should suffice:

{% set classes = entry.children().type('and, class, tour') %}


{% set classes = entry.children().type('not category') %}

But both return no results because AND and NOT don't seem to work with entry types (I'm not the only one to have noticed this). Instead, fetch the two entry types separately and merge:

 {% set classes = entry.children().type('class') %}
 {% set classes = classes | merge(entry.children().type('tour')) %}