Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-16T15:49:25.570Z
Comments.Text: 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.
Comments.UserDisplayName: James Smith
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-18T09:52:03.343Z
Comments.Text: 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?
Comments.UserDisplayName: Andreas
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-18T15:33:52.250Z
Comments.Text: No worries, I'm sure there's a way!
Comments.UserDisplayName: James Smith
Tags: <structure><children><sort>
Title: Order structure entries by children's custom date field
ThreadText: # 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
  
  