<p>You need to exclude the ids in order to achieve your goal. So instead of <code>relatedTo not</code> you need a normal related to but the <code>not</code> statement in your id</p>

<p>I'm not on my computer currently so I'll edit the exact code in about 2h but it's the same like that one 
<a href="https://craftcms.stackexchange.com/a/22532/5557">https://craftcms.stackexchange.com/a/22532/5557</a></p>

<p><code>id.('and, not ' ~ idsOfEntriesYouWantToExclude|join(', not ')</code>
Is the important part. In order to get them you just select all entries that are related to the thing you want to exclude </p>

<p><strong>Edit</strong><br>
untested but this should do it</p>

<pre><code>{% relatedEntries = craft.entries.relatedTo(status).ids() %}
{# just for debugging to test if the queryString is correct #}
{% set queryString = 'not ' ~ relatedEntries|join(', not ') %}
{% set results = craft.entries({
    id: 'and, ' ~ queryString,
    section: 'properties',
    price: range,
    search: query.location,
    order: priceDesc
}) %}
</code></pre>

CC BY-SA 3.0
2017-10-27T15:16:41.947Z
Thanks Robin! I had not thought of that approach. FYI for future reference, I finally got `relatedTo: ['or', catId1, catId2, ...]` to work. It looks like that parameter accepts 'or' and 'and', but not 'not'. My category list has 4 items and I was trying to exclude one, so I set my category ids to `craft.categories.id('not' ~ omitCatId).ids()`, then merged `['or]' to it and passed the array to relatedTo.
Joshua
CC BY-SA 3.0
2017-10-27T04:45:50.423Z
2017-10-27T18:05:37.810Z
2017-10-27T18:05:37.810Z
Robin Schambach
<p>I have a search page that filters with these params:</p>

<pre><code>{% set results = craft.entries({
    section: 'properties',
    price: range,
    search: query.location,
    relatedTo: status,
    order: priceDesc
}) %}
</code></pre>

<p>The <code>status</code> variable needs to be set to a 'not' this category (or an array of all the other categories), but I can't seem to phrase my param correctly.</p>

<p>I've tried both the string and array method with category ID's, like this:</p>

<p><code>relatedTo: ['not', category.id]</code></p>

<p>And this:</p>

<p><code>relatedTo: ['or', category1.id, category2.id, ...]</code></p>

<p>Advice?</p>

<entries><categories><relatedto><filtering>
Pass 'not' category.id to relatedTo in Craft
# Pass 'not' category.id to relatedTo in Craft

(Asked by: username_0 on 2017-10-26)

I have a search page that filters with these params:
{% set results = craft.entries({
    section: 'properties',
    price: range,
    search: query.location,
    relatedTo: status,
    order: priceDesc
}) %}

The status variable needs to be set to a 'not' this category (or an array of all the other categories), but I can't seem to phrase my param correctly.
I've tried both the string and array method with category ID's, like this:
relatedTo: ['not', category.id]
And this:
relatedTo: ['or', category1.id, category2.id, ...]
Advice?

**Tags:** entries, categories, relatedto, filtering


---

## 1 answers

### Answer by username_1 on 2017-10-27. Score: 1

You need to exclude the ids in order to achieve your goal. So instead of relatedTo not you need a normal related to but the not statement in your id
I'm not on my computer currently so I'll edit the exact code in about 2h but it's the same like that one 
https://craftcms.stackexchange.com/a/22532/5557
id.('and, not ' ~ idsOfEntriesYouWantToExclude|join(', not ')
Is the important part. In order to get them you just select all entries that are related to the thing you want to exclude 
Edit
untested but this should do it
{% relatedEntries = craft.entries.relatedTo(status).ids() %}
{# just for debugging to test if the queryString is correct #}
{% set queryString = 'not ' ~ relatedEntries|join(', not ') %}
{% set results = craft.entries({
    id: 'and, ' ~ queryString,
    section: 'properties',
    price: range,
    search: query.location,
    order: priceDesc
}) %}

> **Comments:**
> **username_0**: Thanks Robin! I had not thought of that approach. FYI for future reference, I finally got `relatedTo: ['or', catId1, catId2, ...]` to work. It looks like that parameter accepts 'or' and 'and', but not 'not'. My category list has 4 items and I was trying to exclude one, so I set my category ids to `craft.categories.id('not' ~ omitCatId).ids()`, then merged `['or]' to it and passed the array to relatedTo.  

---

