<p>I figured it out! </p>

<p>If anyone is stuck at the same place here’s my solution:</p>

<pre><code>{# category is 'ford' #}
{% set entries = craft.entries.section('support').relatedTo(category).find() %}
{% set partsCategories = craft.categories.group('partsGroup').relatedTo(entries) %}

{# Partslist #}
{% for partsCategory in partsCategories %}

    {{partsCategory.title}}
    {% for part in craft.entries.relatedTo([
      'and',
      { targetElement: partsCategory },
      { targetElement: category }
    ]) %}

      {{part.title}}

    {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-03-18T13:13:14.933Z
2016-03-18T13:13:14.933Z
Robin Sandborg
<p>Does anyone know if you can work with <code>releatedTo</code> between categories? I’d like to get all the categories in a <code>categories.group</code>s that are related to a single category</p>

<p>I have some entries in a channel, lets call it <code>parts</code>. The <code>parts</code> have two categories from two separate groups.</p>

<ul>
<li>Group 1 is <code>partType</code> which has the categories <code>engine</code> <code>interior</code> and <code>transmission</code></li>
<li>Group 2 is <code>manufacturer</code> which has the categories <code>ford</code> and <code>chrysler</code>.</li>
</ul>

<p>On the category-page for <code>ford</code>, i’d like to list all the <code>parts</code> in the <code>ford</code> category, grouped by <code>partType</code></p>

<p>But I don’t wand to show the <code>partType</code> categories that have no <code>parts</code> by the current <code>manufacturer</code></p>

<categories><relations><category>
Working with multiple categories
# Working with multiple categories

(Asked by: username_0 on 2016-03-18)

Does anyone know if you can work with `releatedTo` between categories? I’d like to get all the categories in a `categories.group`s that are related to a single category

I have some entries in a channel, lets call it `parts`. The `parts` have two categories from two separate groups.

* Group 1 is `partType` which has the categories `engine` `interior` and `transmission`
* Group 2 is `manufacturer` which has the categories `ford` and `chrysler`.

On the category-page for `ford`, i’d like to list all the `parts` in the `ford` category, grouped by `partType`

But I don’t wand to show the `partType` categories that have no `parts` by the current `manufacturer`

**Tags:** categories, relations, category

---

## 1 answers

### Answer by username_0 on 2016-03-18. Score: 3

I figured it out! 
If anyone is stuck at the same place here’s my solution:
{# category is 'ford' #}
{% set entries = craft.entries.section('support').relatedTo(category).find() %}
{% set partsCategories = craft.categories.group('partsGroup').relatedTo(entries) %}

{# Partslist #}
{% for partsCategory in partsCategories %}

    {{partsCategory.title}}
    {% for part in craft.entries.relatedTo([
      'and',
      { targetElement: partsCategory },
      { targetElement: category }
    ]) %}

      {{part.title}}

    {% endfor %}
{% endfor %}


---

