Skip Navigation

[Resolved] Get related posts IDs from association ID

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by stefanoT-2 1 year, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2502065

Hello,
I'm using random numbers just for the example of the situation.

I have two posts, of two different post types, with ID "111" and "999", and a many-to-many relationship called "client-listing".
The two posts ("111" and "999") are related and their association's ID is "555".

How can I get the two post IDs ("111" and "999") if I only have the ID of their association ("555")?

Thank you.

#2502585

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

If you know the ID of any of the post elements from a relationship, for example, an intermediary/association post, you can get the other related elements, using the "toolset_get_related_posts" function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

For example, to get the parent and child posts from an intermediary/association post with ID '555', the code will look like this:


$target_association_id = '555';

$get_results = toolset_get_related_posts( $target_association_id, 'recipe-company', 'intermediary', 1, 0, array(), 'post_id', array('parent','child'));

if(!empty($get_results)) {
	$parent_post_id = $get_results[0]['parent'];
	$child_post_id = $get_results[0]['child'];
}

As a result, you'll have the IDs of the related parent and child posts, in the variables '$parent_post_id ' and '$child_post_id', respectively.

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

regards,
Waqar

#2502905

This is exactly what I was looking for. Thank you very much!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.