Skip Navigation

[Resolved] Can’t sort view results using a M2M intermediary post field

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

Problem:

I am trying to sort view results using a M2M intermediary post field but it shows "No results found".

Solution:

Views plugin is using wordpress class WP_Query to query the posts, so if you are ordering the result by custom field, then all posts should have the value in this custom field.

In your case, I suggest you setup a post view, query posts of the intermediary post type, order result by the intermediary post field, in the view's loop display the related(parent) post information:

Relevant Documentation:

https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

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

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

Assisted by: Luo Yang.

Author
Posts
#1124043

I am trying to sort view results using a M2M intermediary post field but it shows "No results found".
I need to sort the custom posts in the relationship "elenco" using a number as sorting priority.
If I change the sorting to Date, title, whatever, it works.

- The intermediary post is public (showui,publicly_queryable, etc).
- The custom field is a number one.
- Al posts have a number value.

Link to a page where the issue can be seen:
hidden link

#1124349

Hello,

Views plugin is using wordpress class WP_Query to query the posts, so if you are ordering the result by custom field, then all posts should have the value in this custom field.

In your case, I suggest you setup a post view, query posts of the intermediary post type, order result by the intermediary post field, in the view's loop display the related(parent) post information:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

#1126528

Hi Luo,

Thats is what we done and it says "No results found".
Do you need some screenshot?

#1127276

Please check these:
1) Make sure the custom number field is registered to the intermediary post type , all intermediary posts should have the value in this custom field
2) If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL and view URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1127963

Thanks for the details, I am downloading the file, will update here if there is anything found

#1127979

As I mentioned above, this post view need to query the intermediary post type, I have done below modification in your website:
Edit the post view "Pelicula Elenco ficha":
hidden link

In section "CONTENT SELECTION" choose option "Elenco Intermediary Posts" instead of "Personas"

In section "Loop item in Pelicula Elenco ficha", you can use the field shortcode directly, for example:

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

More help:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

#1127986

Great! Luo, many thanks for helping me. It was easy at the end.

#1128081

Hi, Sorry for reopening, could you delete the images in the first post?
I tried but there isn't an option to do it.
Thanks!

#1128083

As your request, those images are deleted.

#1132140

My issue is resolved now. Thank you!

#1132450

You are welcome