Skip Navigation

[Resolved] Loop through the repeatable field groups using PHP code

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

Problem:
Loop through the repeatable field groups using PHP code

Solution:
To query the repeating field group posts using PHP - you can use the post relationship API function toolset_get_related_posts .

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/loop-through-the-repeatable-field-groups-using-php-code/#post-948459

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

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

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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Zoren_LeoL6293 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#948329

Hello,
Please help on how to loop through the repeatable field groups to display all the are related to a specific post using PHP code?
Best regards

#948459

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - to query the repeating field group posts using PHP - you can use the post relationship API function toolset_get_related_posts .

For example:

 $child_columns = toolset_get_related_posts(
  $post->ID,     // the parent post / post ID for which you want to display the related post
  'rfg-slug',   //    replace your original the repeating field group slug 
  'parent',     // 
  200,     // the maximum number of results
  0,           // the offset
  array('meta_key'=>'toolset-post-sortorder'),     // additional query arguments
  'post_object',   // return format
  'child',    // role to return
  'meta_value_num',
  'ASC'
  );

 
foreach($child_columns as $column){
       ///    ...do stuff related to rendering the information 
 }

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

#948751

Alright, thank you.