Skip Navigation

[Gelöst] Retrieving multiple child post IDs

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Retrieving multiple child post IDs based on parent post ID using post relationship API

Solution:
You should use the Post Relationship API function toolset_get_related_posts in this case to retrieve all related posts.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/retrieving-multiple-child-post-ids/#post-1079482

Relevant Documentation:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

This support ticket is created vor 6 Jahren, 3 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Farrel vor 6 Jahren, 3 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1078801

Hi

I'm having a problem getting multiple child ids. I'm using this to get the parent ID without a problem.

$parent_id = toolset_get_related_post( $id, 'doctors-at-clinic', 'parent');

Then I'm using this to get the children of the parent

$location_id = toolset_get_related_post( $parent_id, 'clinic-location', 'child');

If there is one child I get the ID but not for several children. I've tried using arrays but I'm not having any success.

Can you please help with the code. I just need each child post ID

Thanks

#1079482

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Post relationship API function toolset_get_related_post is set to return only 1 value. As you can see with the following Doc:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

You should use the Post Relationship API function toolset_get_related_posts in this case to retrieve all related posts.
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

For example:

 $related_post_ids = toolset_get_related_posts(
                                     $parent_id,
                                     'clinic-location',
                                      'parent',
                                      100,
                                       0,
                                       array(),
                                      'post_id',
                                      'child'
                                      );

#1079628

Thanks Minesh! That worked great.

I added this and I was able to get each ID which is what I needed.

foreach ($related_post_ids as $related_post_ids) {
echo $related_post_ids;
}