Saltar navegación

[Cerrado] get parent post by child post id

This support ticket is created hace 3 años, 5 meses. 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.

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel hace 3 años, 5 meses.

Autor
Mensajes
#2296669

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?

#2296783

Nigel
Colaborador

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+01:00)

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

El debate ‘[Cerrado] get parent post by child post id’ está cerrado y no admite más respuestas.