How can I order a sections entries by their children entry postDate? 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') %}
    &lt;a href="{{ article.url }}"&gt;{{ article.title }}&lt;/a&gt;
{% endfor %}


Each article has 1 child under it. I want to filter the articles by the latest postDate of the children.
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 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 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]) %}