I have two sections: Products (channel) and Accessories (structure).

The Accessories section is a structure and can multiple levels to it, a Product may relate to a child (level 2) but not it's parent (level 1)

I relate a Product to on or many Accessories using the Entries field type in the Product entry section.

What I want to do is list the top level Accessory entries with the total amount of products it relates to, since it could relate to a child of a top level, or even a third level, is it possible to get that count?

{% set accessories = craft.entries().section('accessories') %}

{% for item in accessories.all() %}
    {{ item.title }} (total products that relate to the parent thru a direct relationship or lower level relationship)
{% endfor %}

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.