Skip Navigation

[Closed] Is it possible to "orderby" relationship when using in a WP_Query?

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 3 voices.

Last updated by Minesh 7 months ago.

Assisted by: Minesh.

Author
Posts
#2702890

Tell us what you are trying to do?

I was able to "filter" a query by including the toolset_relationship parameter in a WP_Query based on this documentation: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts

It worked great! But I wonder if it's possible to "orderby" the relation children post title.

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/#wp_query-argument-for-querying-by-related-posts

Thanks in advanced for your help!

#2703087

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I'm not quite sure I follow what you want to do.

The documentation you linked to describes modifying a query so that you filter by a Toolset relationship, e.g. (from the documentation) query books but only return books that are linked to a specified writer post.

We will get back possibly multiple book posts, connected to one writer.

What order do we want to specify?

It is trivial to order by the title of the returned book posts by setting the orderby attribute to 'title'.

You must mean something else, I'm guessing.

#2704408

Hi, thanks for the response.

Let's take that example (one writer with multiple books). As you mentioned, I can use "orderby" = "post_title" to sort all books alphabetically.

But what if I want to order the results, in the same order that the books were connected to the writer?

That's what I'm trying to achieve. Something similar to "orderby" = "relationship_order". Is there a keyword for that?

#2704585

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Here is a sandbox site and you can auto-login to it using the following link:
- hidden link

Can you please setup your post type with post-relationship or you can use existing one and tell me with one example parent and child post what with that keeping in mind what would be your expected results?

The topic ‘[Closed] Is it possible to "orderby" relationship when using in a WP_Query?’ is closed to new replies.