Skip Navigation

[Resolved] Unable to use Intermediary Post Type as a Sort By

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

Problem:

Sort Views query by fields of other post type, and get the result:
no results are returned

Solution:

It is expected result, see the details explanation:
https://toolset.com/forums/topic/unable-to-use-intermediary-post-type-as-a-sort-by/#post-924487

Relevant Documentation:

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

This support ticket is created 6 years, 4 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
- 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 2 replies, has 2 voices.

Last updated by larryB-3 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#924172
Screen Shot 2018-07-12 at 10.13.11 AM.jpg

Tell us what you are trying to do? I have an intermediary post type between Homeowners and Properties that has a field called Status, with values of Current Homeowner, Previous Homeowner and Unoccupied. I would like to be able to sort Homeowners returned in a View by the Intermediary post type field of Status so that Current Homeowners come first, followed by Previous Homeowners, filled by Unoccupied (since these are in alphabetically order).

When setting of the Sort By as shown in the attached screen shot, no results are returned. If I change back to Title or some other Order By choice, my results return. Is this bug or am I doing something wrong?

#924487

Hello,

Yes, it is expected result.

The "Status" fields are in "intermediary post type", there isn't "Status" field in "Homeowner" posts, it conduct the problem:
no results are returned
See wordpress document:
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
'meta_value' - Note that a 'meta_key=keyname' must also be present in the query.

So when your view is querying "Homeowner", you can not order the results by custom fields of other post type.

You can try to create a post view, query "intermediary post type" posts, and order by the "Status" field, and display related "Homeowner" post information

#924667

Thanks! That makes sense.