Navigation überspringen

[Gelöst] Ordering a View by a relationship field

This support ticket is created vor 4 Jahren, 8 Monaten. 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)

Author
Artikel
#1600663

I am trying to:
When showing an Organization post, I want to order the display of People related to that Organization using the relationship field Person Relationship.

Instead, I get "No results found"

When ordering by Post Date, it works fine, and I can actually display the contents of the relationship field Person Relationship.

Here is a video showing the problem.

versteckter Link

Subsequent to creating that video, I discovered the advice here about setting the "show_ui' option

https://toolset.com/forums/topic/sorting-posts-by-intermediary-field/

Oddly, I had NOT set that option, but I WAS able to display the relationship field.

I tried again after setting the "show_ui' option, but again, when trying to order the output by Person Relationship I get "No results found"

#1601661
post-selection.png
edit-wizard.png

Hi, in WordPress post queries it's only possible to order by a field associated with the post type being queried. In other words, if the field is not applied to the Person post type directly you cannot order the View of Persons by that field because the result will be "no items found" as you have noticed. Instead the way to approach this is to expose the intermediary post type in the menu as a public post type and set the Content Selection of the View to be the intermediary post type Organization Persons. You must remove the Persons post type from the Content Selection panel. This will allow you to sort the View based on the intermediary field, but it will break the loop contents because the query no longer queries Persons posts.

Since the Content Selection changed, you'll need to update any shortcodes used in the loop to point to the correct post - i.e. the related Person post. When you insert a shortcode using the Fields and Views button, you will see in the popup a tab "Post Selection", where you will be able to select a related post. In the Loop Wizard, you have a similar opportunity when you add content in the loop. You can click the "Edit" button next to any field here and use the same Post Selection tab to select a related post. See edit-wizard.png and post-selection.png for examples.

Yet another way to enact this change is to manually update any shortcodes using the item attribute and the @relationship-slug.role syntax:

[wpv-post-link item="@relationship-slug.parent"]

You can find the relationship slug and roles by editing this relationship in Toolset > Relationships. Check the checkbox "I understand that changes to these settings may delete post associations in this Relationship" in the Settings panel to see role information (but do not make changes). So if the Person post is actually the child in this m2m relationship and the relationship slug is "organization-person" you would use this syntax in a View of the intermediary post type to display information about the Person post:

[wpv-post-link item="@organization-person.child"]

Let me know if you have questions about that, or if I've misunderstood the issue.

#1601705

OK - I get that, Christian. I'll try one of those options.

But just to check - is it possible to use the item attribute in the Content Template used to display the loop items?

Alex

#1601745

I did try to use the item attribute in the content template shortcode, and that worked perfectly! That turned out to be very easy.

Thanks, Christian

My issue is resolved now. Thank you!