<p>Just to add to the answer above, in plain text the answer would be:</p>
<pre><code>'and, not 1, not 2'
</code></pre>
<p>Or, in an entry query:</p>
<pre><code>    {%- set entries = craft.entries({
      section: 'blog',
      id: 'and, not 123, not 456, not 789',
    }).all() %}
</code></pre>

CC BY-SA 4.0
2020-10-13T17:44:31.077Z
2020-10-13T17:44:31.077Z
tomkiss
<p>In my case I have a set number of chosen entries to exclude so I'll show how to do that first.</p>

<pre><code>{# Build array of chosen council leaders to exclude from council member list since they're already being displayed by using the "merge" Twig filter #}
{% set idsToExclude = ['and'] %} 
</code></pre>

<p>Beginning the array with <code>'and'</code> is the trick here. Without it this won't work.</p>

<pre><code>{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilPresident.first.id]) %}
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilVicePresident.first.id]) %}
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilSecretary.first.id]) %}
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilTreasurer.first.id]) %}

{# Convert the idsToExclude array into a comma separated list #}
{% set idsToExcludeString = idsToExclude|join(', not ') %}

{# Echo out the council members without displaying the featured ones #}
{% for councilMember in peopleEntries.id(idsToExcludeString) %}
  {{ councilMember.title }}
{% endfor %}
</code></pre>

<p>Let's say you want to exclude entries that you've choosen in a entry field. So there's multiple related entries and you've already looped over them to display them on the page but you want to ensure that they aren't displayed later on the page when you list all the entries out.</p>

<p><em>It's fairly similar to the above code but just for the sake of clarity.</em></p>

<pre><code>{# Base array of chosen council members to exclude from council member list since they're already being displayed #}
{% set idsToExclude = ['and'] %} 

{% for item in entry.featuredCouncilMembers %}
  {{ entry.title }}

  {# Build array of chosen council leaders to exclude from council member list since they're already being displayed by using the "merge" Twig filter #}
  {% set idsToExclude = idsToExclude|merge([item.id]) %}
{% endfor %}

{# Convert the idsToExclude array into a comma separated list #}
{% set idsToExcludeString = idsToExclude|join(', not ') %}

{# Echo out the council members without displaying the featured ones #}
{% for councilMember in peopleEntries.id(idsToExcludeString) %}
  {{ councilMember.title }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-12-08T23:00:45.043Z
You might want to check for `idsToExclude` length before joining and passing it to the `id` param, to make sure to not pass a string with 'and'  only. Thanks for the nice post!
carlcs
CC BY-SA 4.0
2023-09-22T13:13:12.633Z
Yes. I've been caught out a lot by this! I used to always create a string of `idsToExclude = [0]` and add to that, but now I will `.id(idsToExclude|length ? 'and, not ' ~ idsToExclude|join(', not ') : null)` which feels a bit cleaner.
ianp
CC BY-SA 3.0
2015-12-08T22:36:45.497Z
2015-12-08T22:36:45.497Z
zackspear
<p>I have a structure <code>people</code> that I need to grab entries from. However, I need to exclude certain entries as some are already displayed on the page in a different manner.</p>

<p>I know that you can exclude a single entry by doing something like this</p>

<pre><code>{% for councilMember in craft.entries.section('people').id('not ' ~ entry.id)
</code></pre>

<p>But how do you exclude multiple entries by their IDs?</p>

<entries><entry><templating><id>
Exclude multiple entries by their IDs
# Exclude multiple entries by their IDs

(Asked by: username_0 on 2015-12-08)

I have a structure people that I need to grab entries from. However, I need to exclude certain entries as some are already displayed on the page in a different manner.
I know that you can exclude a single entry by doing something like this
{% for councilMember in craft.entries.section('people').id('not ' ~ entry.id)

But how do you exclude multiple entries by their IDs?

**Tags:** entries, entry, templating, id

---

## 2 answers

### Answer by username_0 on 2015-12-08. Score: 12 | Accepted answer

In my case I have a set number of chosen entries to exclude so I'll show how to do that first.
{# Build array of chosen council leaders to exclude from council member list since they're already being displayed by using the "merge" Twig filter #}
{% set idsToExclude = ['and'] %} 

Beginning the array with 'and' is the trick here. Without it this won't work.
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilPresident.first.id]) %}
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilVicePresident.first.id]) %}
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilSecretary.first.id]) %}
{% set idsToExclude = idsToExclude|merge([entry.metropolisCouncilTreasurer.first.id]) %}

{# Convert the idsToExclude array into a comma separated list #}
{% set idsToExcludeString = idsToExclude|join(', not ') %}

{# Echo out the council members without displaying the featured ones #}
{% for councilMember in peopleEntries.id(idsToExcludeString) %}
  {{ councilMember.title }}
{% endfor %}

Let's say you want to exclude entries that you've choosen in a entry field. So there's multiple related entries and you've already looped over them to display them on the page but you want to ensure that they aren't displayed later on the page when you list all the entries out.
It's fairly similar to the above code but just for the sake of clarity.
{# Base array of chosen council members to exclude from council member list since they're already being displayed #}
{% set idsToExclude = ['and'] %} 

{% for item in entry.featuredCouncilMembers %}
  {{ entry.title }}

  {# Build array of chosen council leaders to exclude from council member list since they're already being displayed by using the "merge" Twig filter #}
  {% set idsToExclude = idsToExclude|merge([item.id]) %}
{% endfor %}

{# Convert the idsToExclude array into a comma separated list #}
{% set idsToExcludeString = idsToExclude|join(', not ') %}

{# Echo out the council members without displaying the featured ones #}
{% for councilMember in peopleEntries.id(idsToExcludeString) %}
  {{ councilMember.title }}
{% endfor %}

> **Comments:**
> **username_2**: You might want to check for `idsToExclude` length before joining and passing it to the `id` param, to make sure to not pass a string with 'and'  only. Thanks for the nice post!  
> **username_3**: Yes. I've been caught out a lot by this! I used to always create a string of `idsToExclude = [0]` and add to that, but now I will `.id(idsToExclude|length ? 'and, not ' ~ idsToExclude|join(', not ') : null)` which feels a bit cleaner.  

---

### Answer by username_1 on 2020-10-13. Score: 2

Just to add to the answer above, in plain text the answer would be:
'and, not 1, not 2'

Or, in an entry query:
    {%- set entries = craft.entries({
      section: 'blog',
      id: 'and, not 123, not 456, not 789',
    }).all() %}


---

