Link to documentation page: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
This code works for me when a 'sitter' custom post type has a one-to-many with 'products' post type (Sitter is the parent):
new WP_Query(
[
'post_type' => 'product',
'toolset_relationships' => [
'role' => 'child',
'related_to' => $sitter_post,
'relationship' => 'sitter-products'
],
]
);
I didn't actually find *working* code examples *anywhere*.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/ has a "NEW APPROACH" snippet, but I think you should add:
- an explanation of what this relationship is
- an explanation of what this query is expected to return
- fix the 'relationship' to be a string, since an array (['sitter','product']) is for legacy relationships
- a link to the official/current documentation, since https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts seems to be legacy information, as it's not WP_Query
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - I do not know if you missed it by mistake but all available query argument is documented here with the explanation:
=> 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
Now, regarding toolset_get_related_posts() , no its not a legacy function but you should feel free to use it with your new relationships.
For example:
$related_post_ids = toolset_get_related_posts(
$parent_id,
'clinic-location',
'parent',
100,
0,
array(),
'post_id',
'child'
);
Please check this related ticket:
=> https://toolset.com/forums/topic/retrieving-multiple-child-post-ids/#post-1079482
I did miss that bit; thanks for letting me know. Despite this section of text existing, I think the other feedback I had is still applicable.
Hi,
Minesh isn't available, he has one day vacation, you will get the response ASAP when he back on Thursday.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Well - at top of the page we already wrote that:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/
On this page, we will use "legacy" for referring to the old post relationship features before the Types 3.0 release. Please note that the Types 2.2.22 release added the new Post Relationships API to the legacy relationships.
We also added the following that after activating the new post relationships you need to use slug:
However, for relationships created after activating the new post relationships, this will not work and the relationship slug must be used instead.
So It seems all fine here and we can close it here.
I'd ask that your content team look into the readability/clarity of this article based on my feedback.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Yes - I will share your feedback with our Doc team. Thank you. Feel free to close this ticket.
Thank you for having your Doc Team review this article for easy/clear understanding via quick reference.