Tell us what you are trying to do?
I am running a function upon submitting a form that edits custom fields on an intermediary post.
I would like to create an additional function to work with custom fields that exist in both the parent and the child of this relationship that runs when submitting the form.
I need to retrieve the post IDs of the parent and child on the intermediary post the function is running on. I am very clear on how to gather the parent and child ID on a one to many relationship, but this intermediary post issue is quite confusing.
So put simply, I need to know the proper code to get the parent ID and child ID of the current intermediary post.
thank you!
marc
Hi Marc,
Thank you for contacting us and I'd be happy to assist.
You can use the "toolset_get_related_posts" function to get the related parent and the child posts from an intermediary post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Example to get the parent post ID:
$get_parent = toolset_get_related_posts( $intermediary_post_id, $relationship_slug, 'intermediary', 1, 0, array(), 'post_id', 'parent' );
Example to get the child post ID:
$get_child = toolset_get_related_posts( $intermediary_post_id, $relationship_slug, 'intermediary', 1, 0, array(), 'post_id', 'child' );
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
My issue is resolved now. Thank you!