Skip Navigation

[Closed] Get all related posts which has multiple relationship with multiple post types

This support ticket is created 4 years, 5 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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 4 years, 5 months ago.

Author
Posts
#1995627

I have different post types people, news, publication, events. People post type has one to many relationship with news post type (slug name: people-news, 1 People can be assigned to one News -> Infinite News can be assigned to one People). People post type has many to many relationship with events post type (slug name: speakers, Infinite People can be assigned to one Event -> Infinite Events can be assigned to one People ). People post type has many to one relationship with publication post type (slug name: writer, 1 Publication can be assigned to one People -> Infinite People can be assigned to one Publication).

I was using this code to do that:
$peoplePostQueryArr = array(
'post_type' => ['news', 'events', 'publication'],
'posts_per_page'=> 4,
'toolset_relationships' => [

['role' => 'child',
'related_to' => $peopleId,
'relationship' => 'people-news'
],
['role' => 'child',
'related_to' => $peopleId,
'relationship' => 'speakers'
],
['role' => 'child',
'related_to' => $peopleId,
'relationship' => 'writer'
],
]
);

$relatedPosts = new WP_Query($peoplePostQueryArr);

But his code didn't return any result, I want all these toolset relationship works with OR condition. Please show me how to do it.

#1996037

Nigel
Supporter

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

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

Multiple conditions added to the 'toolset_relationship' argument are always evaluated using the AND operator, see: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#full-documentation-of-the-query-argument

It's not possible to specify using 'OR' as an alternative.

If you want to query multiple relationships in that way then it would be necessary to set up separate queries for each relationship, and then combine the results.

The topic ‘[Closed] Get all related posts which has multiple relationship with multiple post types’ is closed to new replies.