Skip Navigation

[Resolved] Query posts Type A in an A-to-B many-to-many, ordered by custom field of Type B

This support ticket is created 2 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2521395

Tell us what you are trying to do?

I have two post types that are used to associate one or more concert posters (i.e. "collectible") with one or more concerts (i.e. "event") via an intermedia post type ("event-collectibles").

The "event" post type has a custom field for "Event Date" ("wpcf-event-date") that stores a unix timestamp.

I would like to query the "collectible" post type to get all collectibles (posts_per_page = -1) sorted by most recent to least recent event date.

Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#new-approach
https://toolset.com/forums/topic/view-orderby-custom-field-not-working/

Is there a similar example that we can see?

I only have examples using the old method using a custom query to join the _wpcf_belongs type fields.

I do not have an example using the new relationships tables.

What is the link to your site?

hidden link

#2522335

Hi,

Thank you for contacting us and I'd be happy to assist.

The filtering and ordering in query work with the custom fields that are directly attached to a post type. This means that if the custom field "Event Date" is attached to the post type "Events", then to order the results by this field, you'll need to set the view to show the "Events" post type and not the "Collectible" post type.

In the view's individual result or loop item, you can then show the related "Events" post(s), using a nested view with a post-relationship filter.
( guide on nested views: https://toolset.com/documentation/legacy-features/views-plugin/using-a-child-view-in-a-taxonomy-view-layout/ )

Note: The nesting of blocks-based views is not supported, so you'll have to create the child/nested view, using the classic/legacy views editor.

I hope this helps and please let me know if you need further assistance.

regards,
Waqar