Navigation überspringen

[Geschlossen] get parent post by child post id

This support ticket is created vor 3 Jahre, 4 Monaten. 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.

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Nigel vor 3 Jahre, 4 Monaten.

Author
Artikel
#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
Unterstützer

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: 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

Das Thema „[Geschlossen] get parent post by child post id“ ist für neue Antworten geschlossen.