1

I have a section called "lunchMenu" that contains an entries field ("menuItems"). Each entry in "menuItems" is related to a category in the category group ("foodCategory"). I would like to loop through each of the entries only in "lunchMenu" and output them within their respective categories.

When I loop through the entries field alone, everything works just fine. However, when I add the relatedTo parameter to sort by category, I get entries that are not present in this section's entry field.

Here's the code I'm using - any help would be appreciated. I think I'm not understanding the use of the relatedTo correctly.

{% set food = craft.categories.group('foodCategory') %}
{% set entries = craft.entries.section('lunchMenu') %}

    {% for entry in entries %}
        {% for category in food %}
        {{ category.title }}
            {% for item in entry.menuItems.relatedTo(category) %}
                    {{ item.title }}
            {% endfor %}
    {% endfor %}
{% endfor %}

0

Your Answer

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

Browse other questions tagged or ask your own question.