Skip Navigation

[Resuelto] Get related posts IDs from association ID

This support ticket is created hace 2 años. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por stefanoT-2 hace 2 años.

Asistido por: Waqar.

Autor
Mensajes
#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

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!