<p>I've faced this a few times and solved it like this:</p>
<pre class="lang-twig prettyprint-override"><code>{% set entries = craft.entries.section([
    'section1',
    'section2',
    'section3',
]).all() %}

{# group the results by section handle #}
{% set entriesGrouped = entries|group('section.handle') %}

{# use this array to specify a manual order to be used when outputting the results #}
{% set manualSortOrder = [
    'section3',
    'section1',
    'section2',
 ] %}

{# ================================== #}

&lt;ul&gt;
    {% for sectionHandle in manualSortOrder %}
        {% if entriesGrouped[sectionHandle] is defined %}
            {% for entry in entriesGrouped[sectionHandle] %}
                &lt;li&gt;&lt;a href=&quot;{{ entry.url }}&quot;&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
            {% endfor %}
        {% endif %}
    {% endfor %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 4.0
2021-10-06T10:59:46.390Z
Thanks James. This is a nice approach.
Terry Upton
CC BY-SA 4.0
2021-10-06T10:37:58.827Z
2021-10-06T10:37:58.827Z
James Smith
<p>Since posting the original question, I have also solved this like so:</p>
<pre><code>{% set aboutPages = craft.entries.section(['about']).all() %}
{% set newsPage = craft.entries.section('newsIndex').one() %}
{% set aboutNavigation = aboutPages|merge([newsPage]) %}
</code></pre>

CC BY-SA 4.0
2021-10-06T13:17:39.647Z
Bear in mind that this approach will increase your query count, as you're making DB roundtrips every time you call .one() or .all().
James Smith
CC BY-SA 4.0
2021-10-06T10:58:11.763Z
2021-10-06T10:58:11.763Z
Terry Upton
<p>When getting pages from multiple sections like so:</p>
<pre><code>  {% set aboutNavigation = craft.entries
    .section(['about', 'newsIndex'])
    .all() %}
</code></pre>
<p>How can I set order that the sections appear?
So I want the <code>about</code> pages to be ordered first (by their structure order (which works out the box) and then the <code>newsIndex</code> page to be the last page in the order.</p>
<p>How would this also apply if there were more than 2 sections in the array?</p>

<templating><ordering><order><elementquery>
OrderBy section when selecting multiple sections in entries query
# OrderBy section when selecting multiple sections in entries query

(Asked by: username_0 on 2021-10-06)

When getting pages from multiple sections like so:
  {% set aboutNavigation = craft.entries
    .section(['about', 'newsIndex'])
    .all() %}

How can I set order that the sections appear?
So I want the about pages to be ordered first (by their structure order (which works out the box) and then the newsIndex page to be the last page in the order.
How would this also apply if there were more than 2 sections in the array?

**Tags:** templating, ordering, order, elementquery

---

## 2 answers

### Answer by username_1 on 2021-10-06. Score: 2

I've faced this a few times and solved it like this:
{% set entries = craft.entries.section([
    'section1',
    'section2',
    'section3',
]).all() %}

{# group the results by section handle #}
{% set entriesGrouped = entries|group('section.handle') %}

{# use this array to specify a manual order to be used when outputting the results #}
{% set manualSortOrder = [
    'section3',
    'section1',
    'section2',
 ] %}

{# ================================== #}


    {% for sectionHandle in manualSortOrder %}
        {% if entriesGrouped[sectionHandle] is defined %}
            {% for entry in entriesGrouped[sectionHandle] %}
                {{ entry.title }}
            {% endfor %}
        {% endif %}
    {% endfor %}

> **Comments:**
> **username_0**: Thanks James. This is a nice approach.  

---

### Answer by username_0 on 2021-10-06. Score: 1

Since posting the original question, I have also solved this like so:
{% set aboutPages = craft.entries.section(['about']).all() %}
{% set newsPage = craft.entries.section('newsIndex').one() %}
{% set aboutNavigation = aboutPages|merge([newsPage]) %}

> **Comments:**
> **username_1**: Bear in mind that this approach will increase your query count, as you're making DB roundtrips every time you call .one() or .all().  

---

