Answers.Body: <p>This should do what you want.</p>
  
  <pre><code>{% set videos = craft.entries({
      section: 'articles',
      type: 'video',
      level: 2,
  }) %}
  
  {% set articleIds = [] %}
  {% for video in videos %}
      {% set article = video.getParent() %}
      {% set articleIds = articleIds|merge([article.id]) %}
  {% endfor %}
  
  {% set articles = craft.entries({
      id: articleIds,
      fixedOrder: true,
      limit: 6
  }) %}
  </code></pre>
  
  <p>You go through all the videos and collect the IDs of the parent article entries. Once you have the IDs, make sure to set <a href="https://craftcms.com/docs/templating/craft.entries#fixedOrder" rel="nofollow"><code>fixedOrder</code></a> in the final criteria model and the entries are retuned in the same order as the IDs in the <code>id</code> param.</p>
  
  <p>Note that the <a href="https://craftcms.com/docs/templating/entrymodel#getParent" rel="nofollow"><code>getParent</code></a> function queries the database for each video in your section. You might want to consider caching that piece of code.</p>
  
  <p>And you can also test if replacing the code in the for loop with the following performs better.</p>
  
  <pre><code>{% set articleId = video.getAncestors(1).ids()[0] %}
  {% set articleIds = articleIds|merge([articleId]) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-20T02:17:39.553Z
Answers.Text: Thanks a lot, Works great, I don't know that we can use fixedOrder to do that
  
  and using the "id" to get the entries is really something, can't think up of this method at first.
Answers.UserDisplayName: postsrc
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-19T23:51:20.153Z
Answers.LastActivityDate: 2016-07-19T23:51:20.153Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>If I'm reading this correctly, you need two loops: one to loop over the parent entries in the section and then a second to get the parent's children. That'll give you the control you need.</p>
  
  <p>Something like (untested):</p>
  
  <pre><code>{% for parentArticle in craft.entries({ 
             section: 'articles', type: 'videoArticle', limit: 6
          }).order('postDate asc') 
   %}
  
   {# do what you want with the parent, just a heading and description here #}
  
   &lt;h2&gt;{{parentArticle.title}}&lt;/h2&gt;
    {{parentArticle.topLevelDescription}}
  
   {# loop over the children underneath the parent sorted by most recent #}
  
    &lt;ul&gt;
    {% for childArticle in parentArticle.children.order('postDate asc') %}
        &lt;li&gt;&lt;a href="{{childArticle.url}}"&gt;{{childArticle.title}}&lt;/a&gt;
    {% endfor %}
    &lt;/ul&gt;
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-19T20:59:27.233Z
Answers.LastActivityDate: 2016-07-19T20:59:27.233Z
Answers.UserDisplayName: RitterKnight
Body: <p>Is it possible to order a section of entries by their child entries post date?</p>
  
  <pre><code>{% for article in craft.entries({
      section: 'articles',
      type: 'videoArticle',
      limit: 6
  }).getChildren().order('postDate asc') %}
      &lt;a href="{{ article.url }}"&gt;{{ article.title }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>Each article has 1 child under it. I want to filter the articles by the latest postDate of the children.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-22T14:00:27.723Z
Comments.Text: Can you provide a little more information? Is this section a structure?
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T00:05:23.167Z
Comments.Text: @LukePearce yes, i edited the description
Comments.UserDisplayName: postsrc
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T10:52:14.127Z
Comments.Text: I'm struggling to see why you have these entries set up in such a way. What are the child entries within each parent?
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T11:45:36.410Z
Comments.Text: @LukePearce each article have multiple sub sections/children
  
  and I want to sort the article based on the children postDate
Comments.UserDisplayName: postsrc
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T11:47:48.550Z
Comments.Text: Article1 contains (video1, video2, video3) • Article2 contains (Video1, Video2). when i loop the article.getChildren.latest() It will give me the Latest video from Article1 but I want to order the result by video postDate
Comments.UserDisplayName: postsrc
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T11:48:13.073Z
Comments.Text: Ok, but what is the content of the child entries and what is their relationship to the articles? You may be able to set up your site structure differently to achieve what you want.
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T11:50:32.317Z
Comments.Text: For article It's just a short description of the topic and they have multiple sub section/children. I want to sort the article based on the children postDate. If I add new children for article2, article2 will be sorted first
Comments.UserDisplayName: postsrc
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T11:50:48.303Z
Comments.Text: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40164/discussion-between-luke-pearce-and-densityx).
Comments.UserDisplayName: Luke Pearce
Tags: <entries><ordering>
Title: How can I order a sections entries by their children entry postDate?
ThreadText: # How can I order a sections entries by their children entry postDate?
  
  (Asked by: username_0 on 2016-05-22)
  
  Is it possible to order a section of entries by their child entries post date?
  
  ```
  {% for article in craft.entries({
      section: 'articles',
      type: 'videoArticle',
      limit: 6
  }).getChildren().order('postDate asc') %}
      <a href="{{ article.url }}">{{ article.title }}</a>
  {% endfor %}
  
  ```
  
  Each article has 1 child under it. I want to filter the articles by the latest postDate of the children.
  
  **Tags:** entries, ordering
  
  > **Comments:**
  > **username_1**: Can you provide a little more information? Is this section a structure?  
  > **username_0**: @username_1 yes, i edited the description  
  > **username_1**: I'm struggling to see why you have these entries set up in such a way. What are the child entries within each parent?  
  > **username_0**: @username_1 each article have multiple sub sections/children  and I want to sort the article based on the children postDate  
  > **username_0**: Article1 contains (video1, video2, video3) • Article2 contains (Video1, Video2). when i loop the article.getChildren.latest() It will give me the Latest video from Article1 but I want to order the result by video postDate  
  > **username_1**: Ok, but what is the content of the child entries and what is their relationship to the articles? You may be able to set up your site structure differently to achieve what you want.  
  > **username_0**: For article It's just a short description of the topic and they have multiple sub section/children. I want to sort the article based on the children postDate. If I add new children for article2, article2 will be sorted first  
  > **username_1**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40164/discussion-between-username_1-and-densityx).  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-07-19. Score: 3 | Accepted answer
  
  This should do what you want.
  
  ```
  {% set videos = craft.entries({
      section: 'articles',
      type: 'video',
      level: 2,
  }) %}
  
  {% set articleIds = [] %}
  {% for video in videos %}
      {% set article = video.getParent() %}
      {% set articleIds = articleIds|merge([article.id]) %}
  {% endfor %}
  
  {% set articles = craft.entries({
      id: articleIds,
      fixedOrder: true,
      limit: 6
  }) %}
  
  ```
  
  You go through all the videos and collect the IDs of the parent article entries. Once you have the IDs, make sure to set [`fixedOrder`](https://craftcms.com/docs/templating/craft.entries#fixedOrder) in the final criteria model and the entries are retuned in the same order as the IDs in the `id` param.
  
  Note that the [`getParent`](https://craftcms.com/docs/templating/entrymodel#getParent) function queries the database for each video in your section. You might want to consider caching that piece of code.
  
  And you can also test if replacing the code in the for loop with the following performs better.
  
  ```
  {% set articleId = video.getAncestors(1).ids()[0] %}
  {% set articleIds = articleIds|merge([articleId]) %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks a lot, Works great, I don't know that we can use fixedOrder to do that  and using the "id" to get the entries is really something, can't think up of this method at first.  
  
  ---
  
  ### Answer by username_3 on 2016-07-19. Score: 1
  
  If I'm reading this correctly, you need two loops: one to loop over the parent entries in the section and then a second to get the parent's children. That'll give you the control you need.
  
  Something like (untested):
  
  ```
  {% for parentArticle in craft.entries({ 
             section: 'articles', type: 'videoArticle', limit: 6
          }).order('postDate asc') 
   %}
  
   {# do what you want with the parent, just a heading and description here #}
  
   <h2>{{parentArticle.title}}</h2>
    {{parentArticle.topLevelDescription}}
  
   {# loop over the children underneath the parent sorted by most recent #}
  
    <ul>
    {% for childArticle in parentArticle.children.order('postDate asc') %}
        <li><a href="{{childArticle.url}}">{{childArticle.title}}</a>
    {% endfor %}
    </ul>
  
  {% endfor %}
  
  ```
  
  
  ---
  
  