Skip Navigation

[Resolved] Sorting posts by intermediary field

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

Problem: I have post types Bus Stops and Bus Routes in a many-to-many relationship. On the Bus Route post, I want to display a list of related Bus Stops, ordered by a custom field on the relationship (intermediary post type).

Solution: In this case, the intermediary post type must be visible in wp-admin. Either choose that option when creating a new relationship, or enable the "show_ui" option in the post type editor screen Options panel. Then create a View of the intermediary post type, ordered by the custom field. In the Loop editor, display information from the related Bus Stop post as needed.

Relevant Documentation:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

This support ticket is created 4 years, 8 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Greig Neilson 4 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1323797

I have a post type called Bus Routes and a post type called Bus Stops.

A many-to-many relationship exists between these post types.

I need to be able to specify the order of bus stops on a given bus route. How do I create a view that achieves this? I have created a custom field on this relationship but when I add a sort order using this field I get a 'no results found' message.

#1323943

Hi, you can accomplish this by creating the View using the Intermediary post type as the Content Selection. You must do this because there is no way to filter/sort a View of post type A by fields in a related post or relationship. Instead, create the View targeting the intermediary post type. Then in the Loop editor, you can display information from another related post by using the Post Selection tab when you insert a field. Let me know if you have questions about that.

#1323957

Hi Christian, that makes sense. Unfortunately, only the post types are visible in that Content Selection - the intermediary post does not appear.

#1323961

Normally you would choose to display the intermediary post type when creating the relationship. If the relationship already exists, you can go to Toolset > Post Types and edit the intermediary post type. In the Options panel, you can enable the "show_ui" option to see this post type.

#1323991

Work a treat, Christian. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.