Dear Sir/Madam,
Sorry I can't remember where I got the solution if I want to get the child posts by providing the parent post id
$child_posts = toolset_get_related_posts(
$_REQUEST['mid'],
'member-tablet' ,
array(
'query_by_role' => 'parent',
'return' => 'post_object'
)
);
foreach ($child_posts as $child_post) {
the_post( $child_post->ID );
$tablet_price = get_post_meta($child_post->ID, 'wpcf-tablet-price', true);
}
I have a CPT member and tablet, relationship between member and tablet is one-to-many, now I want to get the parent post meta by providing child post id, how can I do that ?
At what situation I should use toolset_get_related_post instead of toolset_get_related_posts, is it depended on one-to-many or many-to-many relationship?
Could you please quote some example to explain?
You would use toolset_get_related_post when there can be only one result, e.g. you are starting with the ID of a child post and you want to get its parent (there can be only one parent, for a given relationship).
You would use toolset_get_related_posts when there could be multiple results, e.g. you are starting with the ID of a parent post and you want to get all of the IDs of all of the child posts for some relationship.
See
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
and
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts