1

I have a set of entries from multiple channels and I want to loop through each section type that is in the set.

Something like

{% set entries = craft.entries.search(query).order('score') %}

{% for entrySection in entries.sections %}
    {{ entrySection.name }}
{% endfor %}

So basically if I have 100 results from across 8 sections, is there a way I can list out those 8 sections separately?

1 Answer 1

2

Try using the group filter

{% set entries = craft.entries.search(query).order('score') %}

{% for sectionName, sectionEntries in entries | group('section.name') %}
    <h2>{{ sectionName }}</h2>

    <ul>
        {% for entry in sectionEntries %}
            <li>{{ entry.title }}</li>
        {% endfor %}
    </ul>
{% endfor %}
0

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.