Skip Navigation

[Resolved] Sorting view by date stored in child post

This support ticket is created 5 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1376779

I have a parent post type called Vehicles and a child post called SOS test.

I want to display a table with sortable columns, using a date field within the child post to sort ASC.

Each parent will have multiple SOS tests, but I am only interested in the date of the most recent test.

My 'parent view' looks fine - I am seeing the most recent SOS test. The problem is that I can't sort by that column.

How can I achieve this?

#1376885

Hello,

There isn't such a built-in feature within Views, Views is using WP_Query to query posts, see WordPress document:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
‘meta_value‘ – Note that a ‘meta_key=keyname‘ must also be present in the query.

Since you are querying Vehicles posts, so you can only order by fields of Vehicles post type, can not order by fields of other post type "SOS test".

You might consider these:
Create a post view:
- Query "SOS test" posts
- Order results by the date field
- Display it's parent Vehicles post information
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent