Skip Navigation

[Resolved] PHP Code for Nested Repeatable groups

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)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 2 years ago.

Assisted by: Minesh.

Author
Posts
#2633855
2023-08-14_17-56-33.png

I have a repeatable Group within a repeatable group. I have no issues getting the data from the first group, but I'm having troubles getting it from the 2nd group.

To get data from the first group I used this code (which works).

$typeArgs = array(
'query_by_role' => 'parent',
'args' => array(
'meta_key' => 'toolset-post-sortorder',
'meta_compare' => 'EXISTS'
),
'orderby' => 'meta_value_num',
'order' => 'ASC',
'return' => 'post_object');
$result = toolset_get_related_posts($post->ID, 'prices', $typeArgs);
$meta = get_post_meta($result[0]->ID);

How can I get the data from the nested group with PHP?

Thanks

#2633925

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The repeating field group is managed as one to many post relationship internally.

So, what you have done to get the first level group information items you will have to add another level the same as first level where you will have to change the 2nd level group slug.

For example:

$typeArgs = array(
'query_by_role' => 'parent',
'args' => array(
'meta_key' => 'toolset-post-sortorder',
'meta_compare' => 'EXISTS'
),
'orderby' => 'meta_value_num',
'order' => 'ASC',
'return' => 'post_object');
$result = toolset_get_related_posts($post->ID, 'prices', $typeArgs);

foreach($result as $k=>$v):

/// 2nd level
$typeArgs_2nd level  = array(
'query_by_role' => 'parent',
'args' => array(
'meta_key' => 'toolset-post-sortorder',
'meta_compare' => 'EXISTS'
),
'orderby' => 'meta_value_num',
'order' => 'ASC',
'return' => 'post_object');

$2nd_level_results = toolset_get_related_posts($v->ID, '2nd-level-rfg-slug', $typeArgs);
endforeach;

Where:
- change '2nd-level-rfg-slug' with your original 2nd level repeating field group slug.

More info:
- https://toolset.com/documentation/customizing-sites-using-php/displaying-repeatable-groups-of-fields/

If you still have issues then please share problem URL and share all details where exactly you want to display what and send me admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.