Skip Navigation

[Resolved] Retrieving multiple child post IDs

This thread is resolved. Here is a description of the problem and solution.

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 5 years, 8 months ago. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

This topic contains 2 replies, has 2 voices.

Last updated by Farrel 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#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

Languages: English (English )

Timezone: 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;
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.