Problem: I would like to know how to loop over repeating field groups with PHP.
Solution:
Use the toolset_get_related_posts API. Each RFG can be accessed as a child, where the post is the parent and the relationship slug is the RFG slug.
$parent = get_post( 12345 ); // the parent post that holds the RFG $sezioni = toolset_get_related_posts( $parent, // the parent post 'sezioni', // the RFG slug 'parent', // the post role in this relationship is 'parent' 1000000, // the maximum number of results 0, // the offset array(), // additional query arguments 'post_id', // return format 'child', // role to return ); // $sezioni is now an array of post IDs for each RFG $sez1 = get_post( $sezioni[0] ); // example, get the first Sezioni RFG ID $pulsanti = toolset_get_related_posts( $sez1, // the parent RFG 'pulsanti', // the RFG slug 'parent', // the sezioni role in this relationship is 'parent' 1000000, // the maximum number of results 0, // the offset array(), // additional query arguments 'post_id', // return format 'child', // role to return ); // $pulsanti is now an array of post IDs for each RFG in $sez1
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
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.
Our next available supporter will start replying to tickets in about 0.26 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 2 voices.
Last updated by 6 years, 4 months ago.
Assisted by: Christian Cox.