<p>You can probably use the <a href="https://craftcms.com/docs/relations#the-relatedTo-param" rel="nofollow"><code>relatedTo</code></a> parameter with multiple relation criteria:</p>

<pre><code>{% set entries = craft.entries.section(['news', 'press']).relatedTo('or',
    { targetElement: newsTypeCategory, field: 'newsTypeCategoryField' },
    { targetElement: pressTypeCategory, field: 'pressTypeCategoryField' }).order('postDate desc') %}
</code></pre>

<p>Note that <code>newsTypeCategory</code> and <code>pressTypeCategory</code> should be category IDs (or CategoryModels) so you might need to pull the relevant categories as well:</p>

<pre><code>{% set newsTypeCategory = craft.categories.group('newstype').slug('someslug') %}
...
</code></pre>

<p>Also note that you'll obviously need to change the <code>field</code> values to the real handles for your Categories fields, in the example criteria above.</p>

<p><em>An alternative approach</em> is to use the <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow">SuperSort plugin</a> to sort two arrays of entries on the <code>postDate</code> attribute:</p>

<pre><code>{% set newsEntries = craft.entries.section('news').relatedTo(newsTypeCategory) %}
{% set pressEntries = craft.entries.section('press').relatedTo(pressTypeCategory) %}
{% set allEntries = newsEntries|merge(pressEntries)|supersort('sortAs', '{ postDate }') %}
</code></pre>

CC BY-SA 3.0
2016-10-21T07:39:34.423Z
2016-10-21T11:02:16.683Z
2016-10-21T11:02:16.683Z
Mats Mikkel Rummelhoff
<p>I know this post is a bit old, but I was looking for a similar solution.</p>
<p>The other solution mentioned helped me get close, but ultimately, I wanted to use a native Twig <a href="https://twig.symfony.com/doc/3.x/filters/sort.html" rel="nofollow noreferrer">sort</a> function, and I came up with this:</p>
<pre><code>{% set one = craft.entries.section('firstSection').limit(10).all() %}
{% set two = craft.entries.section('secondSection').limit(10).all() %}
{% set entries = one|merge(two) %}

{% for entry in entries|sort((a, b) =&gt; a.postDate &lt;=&gt; b.postDate) %}
    {# do stuff here #}
{% endfor %}
</code></pre>
<p>Hope this helps someone else!</p>

CC BY-SA 4.0
2023-10-11T11:59:27.617Z
yes that just helped me a lot!
KSPR
CC BY-SA 4.0
2023-10-11T20:08:39.310Z
Glad it helped! You can also switch to `b.postDate <=> a.postDate` for DESC order.
Dario Zadro
CC BY-SA 4.0
2023-09-25T15:03:34.433Z
2023-09-25T15:03:34.433Z
Dario Zadro
<p>I got a section called <code>news</code> which contain 2 types of entries: 
<code>news</code> and <code>press</code>.</p>

<p>Those entries are linked with 2 different categories :<br>
<code>news</code> entries have category <code>newsType</code><br>
and <code>press</code> entries have category <code>pressType</code>.</p>

<p>In twig template I want to make 2 entries listing:  </p>

<ol>
<li>one from <code>news</code> entries and category <code>newstype = A</code>   </li>
<li>the other from <code>press</code> entries and category <code>presstype = X</code></li>
</ol>

<p>Then merge those 2 lists to display them ordered by <code>publication date</code>?</p>

<entries><merge><query>
Merge two queries of entries ordered by publication date
# Merge two queries of entries ordered by publication date

(Asked by: username_0 on 2016-10-21)

I got a section called `news` which contain 2 types of entries:
`news` and `press`.

Those entries are linked with 2 different categories :  
`news` entries have category `newsType`  
and `press` entries have category `pressType`.

In twig template I want to make 2 entries listing:

1. one from `news` entries and category `newstype = A`
2. the other from `press` entries and category `presstype = X`

Then merge those 2 lists to display them ordered by `publication date`?

**Tags:** entries, merge, query


---

## 2 answers

### Answer by username_1 on 2016-10-21. Score: 3

You can probably use the relatedTo parameter with multiple relation criteria:
{% set entries = craft.entries.section(['news', 'press']).relatedTo('or',
    { targetElement: newsTypeCategory, field: 'newsTypeCategoryField' },
    { targetElement: pressTypeCategory, field: 'pressTypeCategoryField' }).order('postDate desc') %}

Note that newsTypeCategory and pressTypeCategory should be category IDs (or CategoryModels) so you might need to pull the relevant categories as well:
{% set newsTypeCategory = craft.categories.group('newstype').slug('someslug') %}
...

Also note that you'll obviously need to change the field values to the real handles for your Categories fields, in the example criteria above.
An alternative approach is to use the SuperSort plugin to sort two arrays of entries on the postDate attribute:
{% set newsEntries = craft.entries.section('news').relatedTo(newsTypeCategory) %}
{% set pressEntries = craft.entries.section('press').relatedTo(pressTypeCategory) %}
{% set allEntries = newsEntries|merge(pressEntries)|supersort('sortAs', '{ postDate }') %}


---

### Answer by username_2 on 2023-09-25. Score: 1

I know this post is a bit old, but I was looking for a similar solution.
The other solution mentioned helped me get close, but ultimately, I wanted to use a native Twig sort function, and I came up with this:
{% set one = craft.entries.section('firstSection').limit(10).all() %}
{% set two = craft.entries.section('secondSection').limit(10).all() %}
{% set entries = one|merge(two) %}

{% for entry in entries|sort((a, b) => a.postDate <=> b.postDate) %}
    {# do stuff here #}
{% endfor %}

Hope this helps someone else!

> **Comments:**
> **username_3**: yes that just helped me a lot!  
> **username_2**: Glad it helped! You can also switch to `b.postDate <=> a.postDate` for DESC order.  

---

