1

I have a category set up with nested categories so:

Level1 -level2 -level3

In my entries channel each entry can have multiple nested categories so we may have an entry with:

cat1 -subcat1 -level3

cat2 -subcat1 -level3

The second and third levels will have some categories with the same slug names. So how can I pull out entries with relatedTo that will look at the parents of each level and only pull out categories from the correct nest?

------ UPDATE -----

Ok I have come up with a solution that works but if anyone can suggest something better please feel free.

{% set sector = 'cat1' %}
{% set topic = 'subcat1' %} 
{# set entries variable outside of for loop #}
{% set entries = '' %}
{% if topic is defined %}
{% set categories = craft.categories.group('theCategoryHandle').slug(sector).level(1).first() %}
{% set catChildren = categories.level(3).children %}
{% for childCat in catChildren %}
    {% if childCat.slug == topic %}
        {% set entries = craft.entries.section('mySection').relatedTo(childCat).find() %}
    {% endif %}
{% endfor %}
{% endif %}

Your Answer

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

Browse other questions tagged or ask your own question.