Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-15T10:33:09.507Z
Answers.Text: Thanks, how did i miss that?!
Answers.UserDisplayName: Toby Stokes
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-02T14:58:10.657Z
Answers.Text: 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) %}` 
Answers.UserDisplayName: Jeff Irwin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-15T10:04:53.477Z
Answers.LastActivityDate: 2019-04-15T10:04:53.477Z
Answers.UserDisplayName: Jamie Wade
Body: <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>
  
Tags: <templating><craft2>
Title: Maintaining order when getting by entries by ID
ThreadText: # 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?](https://github.com/TopShelfCraft/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) %}`   
  
  ---
  
  