Skip Navigation

[Resolved] ordering by an intermediate post type field

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

Problem: I would like to create a View of posts in a M2M relationship, and I would like to sort the View by a custom field stored on the intermediary post type.

Solution: It is not possible to sort a View of one post type by a custom field applied to another post type. Instead, you can make the intermediary post type visible in wp-admin and create a View of the intermediary post type sorted by the custom field. In the Loop of the View, you can output information about the related posts using Views shortcodes.

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

Last updated by Christian Cox 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1074915

I am trying to:

Link to a page where the issue can be seen:

Hi there,

What I have is two custom types and a many to many relatioship.

Instructions
Steps
Instruction-Steps

I can make a view, which I display via template in an individual instruction.

The template includes four fields I have created for the Steps type -

the title (seperate from the post title)
images
video
discription

In views:

Content selection: Steps
Ordering by Post Title
Filter: In any relationship as related items of the post where this View is shown

works and displays as I would imagine.

I have set up a field for the relationship post type called 'step order number'

When I attempt ordering by this field in views, with all other settings remaining as above, I get 'no items found'

What have I missed?

- Thanks, Chad

#1075152
Screen Shot 2018-08-06 at 4.37.32 PM.png

Hi, it's not currently possible to filter or sort a View of one post type by a custom field on another post type, regardless of their relationship links. If you try to sort a View of one post type by a custom field that does not exist on any of those posts, no posts will appear in the View results.

One way to achieve this type of sorted View is to make the intermediary post type visible in wp-admin. Then you can create a View of the intermediary post type, sorted by the custom field value. In the output of that View, you can display information about the parent post by inserting shortcodes that reference the parent post type. See the attached screenshot for an example where I am inserting a post title with link shortcode. By switching to the "Post selection" tab in the popup, I am able to specify which post I want to reference. You can choose a post related to the current post, set by a Types relationship.

If the intermediary post type you created for the M2M relationship is not visible in wp-admin, you can activate it by going to Toolset > Post Types, then editing the intermediary post type. A hidden post type is in the "Draft" status. You can show the post type by switching that to "Published".