Skip Navigation

[Resolved] Loop and display all parent post then sort order by the date of the child.

This thread is resolved. Here is a description of the problem and solution.

Problem

How to loop and display all parent post, then sort order that list by the date of the child post?

Solution

In a View, you can order by 2 arguments, a primary and secondary, but there is no orderby "the parent post".

As a possible solution, you can create a View, and query the Child Post Type.

Those you can order by their date in the orderby setting.

Then, in the Loop, you will have to call the related parent Posts.

What you can also do is create 2 Views, in one you query the parent post and order it by what you need, in the second View you query the Child posts (that are a child to the post in the loop).
Those you can order again as you need.

Then you insert the second View into the first's View Loop.

Then, the first View is inserted in a page, and will produce this sort of result:

- parent post (ordered by what you chose)
-- child post (ordered by what you chose)
-- child post (ordered by what you chose)
-- child post (ordered by what you chose)
- another parent post (ordered by what you chose)
-- another child post (ordered by what you chose)
-- another child post (ordered by what you chose)
-- another child post (ordered by what you chose)
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#623877

Hello good day,
I just wanna ask on how to loop and display all parent post then sort order by the date of the child post?
Thanks

#623958

It's not possible.

In a View, you can order by 2 arguments, a primary and secondary, but there is no orderby "the parent".
You can create a View, and query the Child Posts.

Those you can order by their date.
Then, in the Loop, you will have to call the related parent Posts.
But those will be added as ordered by the currently queried post - hence following the orderby as set in the View, which applies to the date of the child.

What you can also do is create 2 Views, in one you query the parent post and order it by what you need, in the second View you query the Child posts (that are child to the post in the loop).
Those you can order again as you need.

Then you insert the second View into the first's View Loop.

Then, the first View is inserted in a page, and will produce this sort of result:
- parent post (ordered by what you chose)
-- child post (ordered by what you chose)
-- child post (ordered by what you chose)
-- child post (ordered by what you chose)
- another parent post (ordered by what you chose)
-- another child post (ordered by what you chose)
-- another child post (ordered by what you chose)
-- another child post (ordered by what you chose)