Skip Navigation

[Resolved] Write a query for repeating field groups

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

Problem: I would like to query repeating field groups.

Solution: The repeating field groups query API is not yet complete.

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

Tagged: 

This topic contains 7 replies, has 3 voices.

Last updated by Christian Cox 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#630204
fields.png

Tell us what you are trying to do?
I need a query to receive all Items from a repeatable field group of a page.

Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

I am using the latest Types beta and I do not use any post relationships, I just created a repeatable group.

I do not get any results if I use the new toolset_relationships paramter:

...
'toolset_relationships' => array(
'role' => 'child',
'related_to' => $post->ID,
'relationship' => array( 'page', 'anchors-group' )
),
...

Right now I create a new query this way but this cant be the way.

$posts = $wpdb->get_results("SELECT child_id FROM website_toolset_associations WHERE parent_id = $post->ID");
$posts_array = [];
foreach ($posts as $post) {
array_push($posts_array, $post->child_id);
}
$anchors = get_posts(
array(
'meta_key' => 'toolset-post-sortorder',
'order' => 'asc',
'orderby' => 'meta_value',
'post__in' => $posts_array,
'post_status' => 'publish',
'post_type' => 'anchors-group',
'posts_per_page' => -1,
)
)

Thx for your help 🙂

#630258

As far I know the published API is for the post relationships, not repeatable field groups.

I think the API to get repeatable Field groups has still to be published.

As well, Toolset will not require custom code to get those values.
They can be displayed in Posts by our ShortCodes and in Views as well the same way, where you can also query by "Repeatable field groups".

Custom fields are still native post meta, so with a simple get_post_meta you will receive that data.
meta key is "_types_repeatable_field_group_post_type" and meta value is a comma-separated value of "The slug you gave to the field"
The single values are to be accessed with simple get_post_meta, where the key is always as used to be, the slug of the field with a wpcf-prefix.

Can you elaborate to me what exactly you would need, so I can suggest the right API to the DEV as well?

#630293
repeatable.png

Thank you 🙂

I will try to explain it better.

I have a page and a custom field with a repeatable field group.
I want to write a query to display all repeated field group posts.

The only connection between the page and the repeated items I found was in "website_toolset_associations".
You mentioned the "_types_repeatable_field_group_post_type" meta key. How can I write a query with this information? I think I just don't get it 🙁 Sorry

Right now I just found this way

$posts = $wpdb->get_results("SELECT child_id FROM website_toolset_associations WHERE parent_id = $post->ID");
#630298

I got it, sorry, I misunderstood you earlier.

I am off right now and will be back only Tuesday.

If you can wait, I will reply here.

If this is urgent - or you plan to proceed to work on this right now, please let me know so I will unassign this ticket from me, and Monday the latest you would get a reply here from other supporters.
(Easter time may show some delay in the usual response time though)

Please let me know.

#630302

No Problem, Tuesday is fine 🙂
Thx and happy easter ?

#630364

Hi, right now the method you described is the only way to access repeating field groups (RFGs) in PHP:

$posts = $wpdb->get_results("SELECT child_id FROM website_toolset_associations WHERE parent_id = $post->ID");

This will give you an array of all the RFG posts, then you can loop over those and call get_post_meta on each RFG post to get the values of each custom field. The custom fields are still saved in postmeta using the key 'wpcf-' + slug, associated with the RFG post ID. Let me know if you have questions about that.

If you simply want to display repeating field groups on the front-end of the site, no PHP query is necessary. You can use a View to loop over the related RFGs and display custom field values in a list.

#630522

Thank you Christian. Ok, then I'll go by the get_results way by now. Can you tell me if there will be a RFG Api some time soon?

#630595

I don't have a timeline available for updated beta features, unfortunately. The best place to stay up-to-date with that information is our blog: https://toolset.com/blog