Tell us what you are trying to do?
I would like to add all related parents posts informations to a response of REST API endpoint.
If I can have all the ids, that will be create, if I can have all the meta fields, that will be better.
Is there any documentation that you are following?
this solution work only for single post_id https://toolset.com/forums/topic/relationship-in-api-rest-2/
I can't figure out, how to use "toolset_get_related_posts" instead of "toolset_get_related_post".
Hello. Thank you for contacting the Toolset support.
I would like to know what relationship you are having - one -2-one or one-2-many?
Also, as I understand you want to get parent post based on the child post ID - is that correct? if yes, so in one-2-many post relationship when you pass child post ID it will have only one parent so in that case you should use toolset_get_related_post()
I have two custom posts, "compagnies" and "membres" and a relationship many-to-many "compagnie-membre".
So one child "membres" can I have many parents "compagnies" and one parent "compagnies" can I have many child "membres".
I presume it's a one-2-many., if I understand well.
The goal it's to get all parents "compagnies" from one child post_id "membres", by using REST API GET.
function get_parent_page_for_api_promociones( $object ) {
//get the id of the post object array
$post_id = $object['id'];
$result = toolset_get_related_posts(
$post_id, // get posts related to the current post (product)
'compagnie-membre', // relationship between the posts
'child', // get posts where product is the child in given relationship
999, 0, // pagination
array(), // no extra args needed here
'post_object', // return post objects
'parent' // return the related parent post(s) in this relationship
);
return $result;
}
function get_parent_page_for_api_compagnie_membre ( $object ) {
//get the id of the post object array
$post_id = $object['id'];
$result = toolset_get_related_posts(
$post_id, // get posts related to the current post (product)
'compagnie-membre', // relationship between the posts
'child', // get posts where product is the child in given relationship
999, 0, // pagination
array(), // no extra args needed here
'post_object', // return post objects
'parent' // return the related parent post(s) in this relationship
);
This is custom code and its beyond the scope of our support policy.
However, to get the taxonomy terms and custom fields attach to your parent, you should loop through the found parents one by one and use wp_get_object_terms() function to get related post terms and use get_post_meta() function to get related post custom field values and build array that holds basic parent post information with taxonomy terms and custom field values and return that array.