<p>I have entries as a structure (<code>trainings</code> ). The top-level elements are trainings (entry type <code>training</code>). Each training can have multiple children which represent training dates (entry type <code>trainingDate</code>). The dates are saved in a date field <code>startDate</code></p>
<p>Trainings are related to one or more categories.</p>
<p>I want to show an overview page where trainings are ordered by their children's start date field. They should also be filtered by category (if a category is selected) and still be ordered by children's date.</p>
<p>This is what I have so far:</p>
<pre><code>{% if category is defined %}
   {% paginate craft.entries.section('trainings').trainingCategory(category).level(1).limit(8) as pageInfo, trainings %}
{% else %}
   {% paginate craft.entries.section('trainings').level(1).order.limit(8) as pageInfo, trainings %}
{% endif %}
</code></pre>
<p>This gives me the trainings in the sort order of the structure.
How can I bring in the children's start date field?</p>

CC BY-SA 4.0
2024-02-16T15:49:25.570Z
I suspect you're trying to solve the wrong problem here: if it's not too late, I'd consider redoing your content model to avoid this. Semantically the parents are not the same thing as the children (sounds like they're probably a type of training, as opposed to an individual course?). These should ideally be two separate content types, tied together with relationships. You'll constantly be running into these kind of problems with the wrong content model.
James Smith
CC BY-SA 4.0
2024-02-18T09:52:03.343Z
Hm, had a feeling that this is the wrong way to do it. Unfortunately, it is too late. There are other things on the site that depend on this structure. Can't change it now. Is there absolutely no way to handle this?
Andreas
CC BY-SA 4.0
2024-02-18T15:33:52.250Z
No worries, I'm sure there's a way!
James Smith
<structure><children><sort>
Order structure entries by children's custom date field
# Order structure entries by children's custom date field

(Asked by: username_0 on 2024-02-16)

I have entries as a structure (trainings ). The top-level elements are trainings (entry type training). Each training can have multiple children which represent training dates (entry type trainingDate). The dates are saved in a date field startDate
Trainings are related to one or more categories.
I want to show an overview page where trainings are ordered by their children's start date field. They should also be filtered by category (if a category is selected) and still be ordered by children's date.
This is what I have so far:
{% if category is defined %}
   {% paginate craft.entries.section('trainings').trainingCategory(category).level(1).limit(8) as pageInfo, trainings %}
{% else %}
   {% paginate craft.entries.section('trainings').level(1).order.limit(8) as pageInfo, trainings %}
{% endif %}

This gives me the trainings in the sort order of the structure.
How can I bring in the children's start date field?

**Tags:** structure, children, sort
> **Comments:**
> **username_1**: I suspect you're trying to solve the wrong problem here: if it's not too late, I'd consider redoing your content model to avoid this. Semantically the parents are not the same thing as the children (sounds like they're probably a type of training, as opposed to an individual course?). These should ideally be two separate content types, tied together with relationships. You'll constantly be running into these kind of problems with the wrong content model.  
> **username_0**: Hm, had a feeling that this is the wrong way to do it. Unfortunately, it is too late. There are other things on the site that depend on this structure. Can't change it now. Is there absolutely no way to handle this?  
> **username_1**: No worries, I'm sure there's a way!  

---

## 0 answers

