How do I loop through and access all sections of returned entries? On my search results page I want to add a section filter depending on the different sections that are included in all of the returned entries.

I am getting all the sections like this:

{% set entries = craft.entries.section(['inspirationArticles', 'pages', 'pressArticles', 'products']).search(searchQuery).order('score') %}
{% set entrySections = entries.getAllSections() %}


And then loop through them:

{% for entrySection in entrySections %}
...
{% endfor %}


But when trying to access the sections’s names or handles via {{ entrySection.name }} or {{ entrySection.handle }}, I get a CException error:

Craft\EntryModel and its behaviors do not have a method or closure named "handle".


So it looks like it isn't actually accessing the SectionModel. Am I missing a step?
Entries to not have a getAllSections method. You can use the group filter to group your entries by their sections.

{% set entries = craft.entries.section(['inspirationArticles', 'pages', 'pressArticles', 'products']).search(searchQuery).order('score') %}
{% set grouped = entries|group('section') %}

{% for section, entriesInGroup in grouped %}
    &lt;h2&gt;Section: {{ section }}&lt;/h2&gt;

    &lt;ul&gt;
        {% for entry in entriesInGroup %}
            &lt;li&gt;{{entry}}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}


Here's some documentation to help!