2

Does anyone know if you can work with releatedTo between categories? I’d like to get all the categories in a categories.groups 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

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 %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.