Answers.Body: <p>Rather than fetching the entries at first, just grab their IDs using <code>ids()</code> instead of <code>find()</code>:</p>
  
  <pre><code>{% set featuredBlogId = craft.entries.section('blogs').limit(1).ids() %}
  {% set featuredArticleId = craft.entries.section('articles').limit(1).ids() %}
  {% set featuredSpecialReportId = craft.entries.section('specialReports').limit(1).ids() %}
  {% set featuredInfographicId = craft.entries.section('infographics').limit(1).ids() %}
  </code></pre>
  
  <p>Then merge all of those arrays together:</p>
  
  <pre><code>{% set featuredIds = featuredBlogId
      |merge(featuredArticleId)
      |merge(featuredSpecialReportId)
      |merge(featuredInfographicId) %}
  </code></pre>
  
  <p>Once you’ve got that array of all the latest featured entries’ IDs, you can fetch their full entry models all at once:</p>
  
  <pre><code>{% set featuredEntries = craft.entries.id(featuredIds) %}
  
  {% for entry in featuredEntries %}
      {{ entry.title }}&lt;br&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-24T12:27:14.940Z
Answers.Text: this seems to be much more efficient but then how do I order the `featuredEntries ` collection by date descending? I want the latest item to show up first!
Answers.UserDisplayName: Amit Erandole
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-24T12:29:24.973Z
Answers.Text: @AmitErandole Entry queries always fetch the entries in order of post date (desc) by default, but if you want to be explicit you can add `.order('postDate desc')` to each of the `craft.entries` calls.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-24T12:16:47.237Z
Answers.LastActivityDate: 2015-11-24T12:16:47.237Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I want to create a featured story slider on my website and gather the <em>latest</em> entries from multiple channels to populate it.</p>
  
  <p>Here is what is working:</p>
  
  <pre><code># fetch the entries
  {% set featuredBlog = craft.entries.section('blogs').limit(1).find() %}
  {% set featuredArticle = craft.entries.section('articles').limit(1).find() %}
  {% set featuredSpecialReport = craft.entries.section('specialReports').limit(1).find() %}
  {% set featuredInfographic = craft.entries.section('infographics').limit(1).find() %}
  
  # create a collection out of the above entries
  {% set allEntries =
  featuredBlog|merge(featuredArticle)|merge(featuredSpecialReport)|merge(featuredInfographic) %}
  
  # loop over the collection and output them
  {% for featuredEntry in allEntries %}
    {{ featuredEntry.title }}&lt;br&gt;
  {% endfor %}
  </code></pre>
  
  <p>Now I want to sort the collection of entries by <code>postDate</code> so that the latest entry in the collection shows up first, no matter what section it is from. How do I do this?</p>
  
  <p>I tried:</p>
  
  <pre><code>{% for featuredEntry in allEntries|group('postDate.day') %}
    {{ featuredEntry.title }}&lt;br&gt;
  {% endfor %}
  </code></pre>
  
  <p>But this doesn't work and crashes the template saying <code>Key "title" for array with keys "0, 1, 2" does not exist</code></p>
  
  <p>So how do I sort a collection of entries from multiple sections and show them by latest date descending?</p>
  
Tags: <sections><sorting><queries>
Title: How do I sort a collection of entries from multiple sections by date?
ThreadText: # How do I sort a collection of entries from multiple sections by date?
  
  (Asked by: username_0 on 2015-11-24)
  
  I want to create a featured story slider on my website and gather the *latest* entries from multiple channels to populate it.
  
  Here is what is working:
  
  ```
  # fetch the entries
  {% set featuredBlog = craft.entries.section('blogs').limit(1).find() %}
  {% set featuredArticle = craft.entries.section('articles').limit(1).find() %}
  {% set featuredSpecialReport = craft.entries.section('specialReports').limit(1).find() %}
  {% set featuredInfographic = craft.entries.section('infographics').limit(1).find() %}
  
  # create a collection out of the above entries
  {% set allEntries =
  featuredBlog|merge(featuredArticle)|merge(featuredSpecialReport)|merge(featuredInfographic) %}
  
  # loop over the collection and output them
  {% for featuredEntry in allEntries %}
    {{ featuredEntry.title }}<br>
  {% endfor %}
  
  ```
  
  Now I want to sort the collection of entries by `postDate` so that the latest entry in the collection shows up first, no matter what section it is from. How do I do this?
  
  I tried:
  
  ```
  {% for featuredEntry in allEntries|group('postDate.day') %}
    {{ featuredEntry.title }}<br>
  {% endfor %}
  
  ```
  
  But this doesn't work and crashes the template saying `Key "title" for array with keys "0, 1, 2" does not exist`
  
  So how do I sort a collection of entries from multiple sections and show them by latest date descending?
  
  **Tags:** sections, sorting, queries
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-24. Score: 3 | Accepted answer
  
  Rather than fetching the entries at first, just grab their IDs using `ids()` instead of `find()`:
  
  ```
  {% set featuredBlogId = craft.entries.section('blogs').limit(1).ids() %}
  {% set featuredArticleId = craft.entries.section('articles').limit(1).ids() %}
  {% set featuredSpecialReportId = craft.entries.section('specialReports').limit(1).ids() %}
  {% set featuredInfographicId = craft.entries.section('infographics').limit(1).ids() %}
  
  ```
  
  Then merge all of those arrays together:
  
  ```
  {% set featuredIds = featuredBlogId
      |merge(featuredArticleId)
      |merge(featuredSpecialReportId)
      |merge(featuredInfographicId) %}
  
  ```
  
  Once you’ve got that array of all the latest featured entries’ IDs, you can fetch their full entry models all at once:
  
  ```
  {% set featuredEntries = craft.entries.id(featuredIds) %}
  
  {% for entry in featuredEntries %}
      {{ entry.title }}<br>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: this seems to be much more efficient but then how do I order the `featuredEntries ` collection by date descending? I want the latest item to show up first!  
  > **username_1**: @username_0 Entry queries always fetch the entries in order of post date (desc) by default, but if you want to be explicit you can add `.order('postDate desc')` to each of the `craft.entries` calls.  
  
  ---
  
  