1

I have a Category Group with an Entries field assigned so the admin can select which existing Entries should fall within a given category. An Entry can be assigned to multiple categories.

On the Entry page I want to be able to loop through the categories and only list those where the entry has been included.

There are six categories vs 20 or 30 entries so doing it the other way (assigning a category to the entry) would be cumbersome for end user editing if a new category is added.

I hope that makes sense?

1 Answer 1

1

You just need to check if it's related to the current entry. entry is the entry you're displaying.

{% for category in craft.categories().group('someGroup').relatedTo(entry).all() %}
    {{ category.title }}
{% endfor %}
1
  • Thanks for the answer Simon, it works perfectly :)
    – Martin
    Commented Oct 11, 2019 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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