<p>You can make use of 'not' to exclude items from your parameters. An example of how this would be implemented in the above use case would be as follows</p>

<pre><code>{% set categories = craft.categories.slug( 'not preferential' ) %}
{% set entries = craft.entries.relatedTo( categories ) %}
</code></pre>

<p>If you need to specify category groups or entry sections then use</p>

<pre><code>{% set categories = craft.categories.group( 'groupHandle' ).slug( 'not preferential' ) %}
{% set entries = craft.entries.section( 'sectionHandle' ).relatedTo( categories ) %}
</code></pre>

CC BY-SA 3.0
2016-04-28T10:09:35.530Z
2016-04-28T10:09:35.530Z
Luke Pearce
<p>I've been racking my brains trying to get my head around categories and entries, hopefully someone can help and show me the best way.</p>

<p>I have an entry page with product information and this product is assigned to multiple categories across multiple groups. I need to exclude the category 'preferential' and only show entries that belong to the category group 'offers'. </p>

<p>Here's what I've got so far:</p>

<pre><code>{% set categories = craft.categories.relatedTo(entry) %}    
{% set excludeCat = craft.categories.slug('preferential').first() %}

{% set allIds = [] %}
{% for id in categories.ids() if id != excludeCat.id %}
    {% set allIds = allIds|merge([id]) %}
{% endfor %}

{% set entries = craft.entries.relatedTo(allIds) %}

{% for offer in entries %}                    
    &lt;a href="{{ offer.url }}"&gt;{{ offer.title }}&lt;/a&gt;&lt;br/&gt;
{% endfor %}
</code></pre>

<p>I've tried variations of 'group', 'ids' and 'groupId' but no joy. This is my first Craft CMS build so still learning.</p>

<p>Thanks!</p>

<entries><categories><relations>
Loop through entries that share current entry category and restrict to Cat Group Id
# Loop through entries that share current entry category and restrict to Cat Group Id

(Asked by: username_0 on 2016-04-25)

I've been racking my brains trying to get my head around categories and entries, hopefully someone can help and show me the best way.
I have an entry page with product information and this product is assigned to multiple categories across multiple groups. I need to exclude the category 'preferential' and only show entries that belong to the category group 'offers'. 
Here's what I've got so far:
{% set categories = craft.categories.relatedTo(entry) %}    
{% set excludeCat = craft.categories.slug('preferential').first() %}

{% set allIds = [] %}
{% for id in categories.ids() if id != excludeCat.id %}
    {% set allIds = allIds|merge([id]) %}
{% endfor %}

{% set entries = craft.entries.relatedTo(allIds) %}

{% for offer in entries %}                    
    {{ offer.title }}
{% endfor %}

I've tried variations of 'group', 'ids' and 'groupId' but no joy. This is my first Craft CMS build so still learning.
Thanks!

**Tags:** entries, categories, relations

---

## 1 answers

### Answer by username_1 on 2016-04-28. Score: 4 | Accepted answer

You can make use of 'not' to exclude items from your parameters. An example of how this would be implemented in the above use case would be as follows
{% set categories = craft.categories.slug( 'not preferential' ) %}
{% set entries = craft.entries.relatedTo( categories ) %}

If you need to specify category groups or entry sections then use
{% set categories = craft.categories.group( 'groupHandle' ).slug( 'not preferential' ) %}
{% set entries = craft.entries.section( 'sectionHandle' ).relatedTo( categories ) %}


---

