<p>You can use the Twig <a href="https://craftcms.com/docs/templating/filters#group" rel="noreferrer">group filter</a>.</p>

<pre><code>{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}

{% set entriesBySection = entries|group('section') %}

{% for section, entriesInSection in entriesBySection %}
    &lt;h2&gt;{{ section }}&lt;/h2&gt;

    &lt;ul&gt;
        {% for entry in entriesInSection %}
            &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-02-20T17:45:26.047Z
Brilliant! Do you know also how I could change the order of sections before doing the group filter? Currently it pulls from the section order in the CP.
4midori
CC BY-SA 3.0
2017-02-18T21:43:44.950Z
2017-02-18T21:43:44.950Z
Aaron Berkowitz
<p>How do I group entries by section? I have search results:</p>

<pre><code>{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
</code></pre>

<p>But I want to have</p>

<p><strong>SECTION NAME</strong>
entry 1
entry 4
entry 6</p>

<p><strong>SECTION NAME</strong>
entry 3
entry 12</p>

<p>etc.</p>

<entries><group>
Group entries by section
# Group entries by section

(Asked by: username_0 on 2017-02-17)

How do I group entries by section? I have search results:
{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}

But I want to have
SECTION NAME
entry 1
entry 4
entry 6
SECTION NAME
entry 3
entry 12
etc.

**Tags:** entries, group


---

## 1 answers

### Answer by username_1 on 2017-02-18. Score: 6 | Accepted answer

You can use the Twig group filter.
{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}

{% set entriesBySection = entries|group('section') %}

{% for section, entriesInSection in entriesBySection %}
    {{ section }}

    
        {% for entry in entriesInSection %}
            {{ entry.title }}
        {% endfor %}
    
{% endfor %}

> **Comments:**
> **username_0**: Brilliant! Do you know also how I could change the order of sections before doing the group filter? Currently it pulls from the section order in the CP.  

---

