<p>I have a overview page that combines with two sections (documentation and galleries). Those two sections are attached to a parent Event. So you can select in the event entry a gallery or a documentation entry.</p>

<p>Question: How can i display those in order of the event's entry event day?</p>

<pre><code>{% set entryGalleryIds         = craft.entries.section('gallery').ids() %}
{% set entryDocumentationIds   = craft.entries.section('documentation').ids() %}

{% set allEntryIds = entryGalleryIds|merge(entryDocumentationIds) %}

{% set allEntries = craft.entries.id(allEntryIds)|batch(3) %}
</code></pre>

<p>...</p>

<p>So i'm looking like something as:</p>

<p><code>{% set allEntries = craft.entries.id(allEntryIds).orderBy('events.eventDate desc')|batch(3) %}</code> </p>

<p>Note: When i first query all the projects and then query the related galleries the sorting is gone, because of my id(allEntryIds) filter.</p>

CC BY-SA 4.0
2018-09-22T21:31:33.260Z
And you can't start at the events, looping through them (sorted) and output related galleries or documentations?
Urs
CC BY-SA 4.0
2018-09-23T20:45:19.240Z
Hi Urs, this is an option, but  a) it means entries without a parent won't be show (also not on the end) and b) it feels like bad programming do it this way.
Dave Driesmans
CC BY-SA 4.0
2018-09-24T07:13:04.647Z
Well, if they don't have a parent, they don't have a date to sort by either. So you could output the "orphans" at the end https://craftcms.stackexchange.com/questions/10456/get-entries-not-related-to-categories
Urs
<craft3><relations>
Sorting with reverse relationship
# Sorting with reverse relationship

(Asked by: username_0 on 2018-09-21)

I have a overview page that combines with two sections (documentation and galleries). Those two sections are attached to a parent Event. So you can select in the event entry a gallery or a documentation entry.
Question: How can i display those in order of the event's entry event day?
{% set entryGalleryIds         = craft.entries.section('gallery').ids() %}
{% set entryDocumentationIds   = craft.entries.section('documentation').ids() %}

{% set allEntryIds = entryGalleryIds|merge(entryDocumentationIds) %}

{% set allEntries = craft.entries.id(allEntryIds)|batch(3) %}

...
So i'm looking like something as:
{% set allEntries = craft.entries.id(allEntryIds).orderBy('events.eventDate desc')|batch(3) %} 
Note: When i first query all the projects and then query the related galleries the sorting is gone, because of my id(allEntryIds) filter.

**Tags:** craft3, relations

> **Comments:**
> **username_1**: And you can't start at the events, looping through them (sorted) and output related galleries or documentations?  
> **username_0**: Hi username_1, this is an option, but  a) it means entries without a parent won't be show (also not on the end) and b) it feels like bad programming do it this way.  
> **username_1**: Well, if they don't have a parent, they don't have a date to sort by either. So you could output the "orphans" at the end https://craftcms.stackexchange.com/questions/10456/get-entries-not-related-to-categories  

---

## 0 answers

