<p>Entries to not have a <code>getAllSections</code> method. You can use the <code>group</code> filter to group your entries by their sections.</p>

<pre><code>{% 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 %}
</code></pre>

<p>Here's some <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow">documentation</a> to help!</p>

CC BY-SA 3.0
2015-06-12T17:36:29.647Z
Thanks Aaron, that works like a charm! Though I do kinda wish I could get a way a one less `for loop` to get to the sections’ details, but that's just me being picky ;)
Katrin
CC BY-SA 3.0
2015-06-12T17:07:36.883Z
2015-06-12T17:07:36.883Z
Aaron Berkowitz
<p>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.</p>

<p>I am getting all the sections like this:</p>

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

<p>And then loop through them:</p>

<pre><code>{% for entrySection in entrySections %}
...
{% endfor %}
</code></pre>

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

<pre><code>Craft\EntryModel and its behaviors do not have a method or closure named "handle".
</code></pre>

<p>So it looks like it isn't actually accessing the SectionModel. Am I missing a step?</p>

<sections>
How do I loop through and access all sections of returned entries?
# How do I loop through and access all sections of returned entries?

(Asked by: username_0 on 2015-06-12)

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?

**Tags:** sections

---

## 1 answers

### Answer by username_1 on 2015-06-12. Score: 4 | Accepted answer

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 %}
    Section: {{ section }}

    
        {% for entry in entriesInGroup %}
            {{entry}}
        {% endfor %}
    
{% endfor %}

Here's some documentation to help!

> **Comments:**
> **username_0**: Thanks Aaron, that works like a charm! Though I do kinda wish I could get a way a one less `for loop` to get to the sections’ details, but that's just me being picky ;)  

---

