Problem: I have a M2M relationship set up using an intermediary post type. I would like to use PHP and the post relationships API to query get all related parent posts of a known child post.
Solution: Use this code as a template:
$artists = toolset_get_related_posts( get_the_ID(), // get posts related to the current post (product) 'artiste-product', // relationship between the posts 'child', // get posts where product is the child in given relationship 10, 0, // pagination array(), // no extra args needed here 'post_object', // return post objects 'parent' // return the related parent post(s) in this relationship );
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 5 replies, has 2 voices.
Last updated by 5 years, 9 months ago.
Assisted by: Christian Cox.