<p>You can do this by adding <code>.fixedOrder(true)</code> to your query:</p>

<p><code>{% set ids = ['4213','3200','4204','4212'].fixedOrder(true) %}</code></p>

<p><a href="https://docs.craftcms.com/v3/dev/element-queries/tag-queries.html#fixedorder" rel="noreferrer">https://docs.craftcms.com/v3/dev/element-queries/tag-queries.html#fixedorder</a></p>

CC BY-SA 4.0
2019-04-15T10:33:09.507Z
Thanks, how did i miss that?!
Toby Stokes
CC BY-SA 4.0
2023-05-02T14:58:10.657Z
Came across this trying to pass a list of entry ids from an entry field into a Sprig component with pagination (Craft v4.4.x).
`{% set entryQuery = craft.entries().id(ids).fixedOrder(true).limit(limit) %}` 
Jeff Irwin
CC BY-SA 4.0
2019-04-15T10:04:53.477Z
2019-04-15T10:04:53.477Z
Jamie Wade
<p>I'd like to get a certain set of entries in a specific order, but the element query comes back ordered by the default 'postDate desc'</p>

<pre><code>{% set ids = ['4213','3200','4204','4212']
 %}

{% set orderedEntries = craft.entries().id(ids).order('id').all() %}

{{ dump(orderedEntries.ids) }} &lt;- not the same order as the array!
</code></pre>

<p>It feels like there should be a relatively simple way of doing this in craft/twig, am I missing something? Or should I just resort to <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow noreferrer">SuperSort?</a></p>

<templating><craft2>
Maintaining order when getting by entries by ID
# Maintaining order when getting by entries by ID

(Asked by: username_0 on 2019-04-15)

I'd like to get a certain set of entries in a specific order, but the element query comes back ordered by the default 'postDate desc'
{% set ids = ['4213','3200','4204','4212']
 %}

{% set orderedEntries = craft.entries().id(ids).order('id').all() %}

{{ dump(orderedEntries.ids) }} <- not the same order as the array!

It feels like there should be a relatively simple way of doing this in craft/twig, am I missing something? Or should I just resort to SuperSort?

**Tags:** templating, craft2


---

## 1 answers

### Answer by username_1 on 2019-04-15. Score: 6 | Accepted answer

You can do this by adding `.fixedOrder(true)` to your query:

`{% set ids = ['4213','3200','4204','4212'].fixedOrder(true) %}`

<https://docs.craftcms.com/v3/dev/element-queries/tag-queries.html#fixedorder>

> **Comments:**
> **username_0**: Thanks, how did i miss that?!  
> **username_2**: Came across this trying to pass a list of entry ids from an entry field into a Sprig component with pagination (Craft v4.4.x). `{% set entryQuery = craft.entries().id(ids).fixedOrder(true).limit(limit) %}`   

---

