Skip Navigation

[Resolved] PHP function to get data from a repeating field group

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Clifford 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#911636

I referenced https://toolset.com/documentation/customizing-sites-using-php/displaying-repeating-fields-one-kind/ but wasn't certain if it was for the new repeating fields or the old way of doing things.

I have a repeating field group with a Textfield and a Numeric field and I want to get that field group's data for the current post.
Screenshot: hidden link (expires in 1 month)

Which PHP function do I use?

Thank you.

#911660

Hello,

The Repeating Field groups is based on post type, each instance of Field group is a single post, for example:

1) You need to get the related posts first, you can use Types new API functiontoolset_get_related_posts () to get the related posts of repeating field group:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
You will be able to get the related post IDs

2) Then use post ID to get the post meta value, render each post's custom field with Types function types_render_field():
https://toolset.com/documentation/customizing-sites-using-php/functions/

More help:
https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/#displaying-repeatable-field-groups

See screenshot:
hidden link

#911951

I get the post IDs from `toolset_get_related_posts()` but what do I use within `foreach`?

`types_render_field()` takes the custom field slug but can't take a specific Post ID, correct?

So does this mean I need to use `get_post_meta()`, or does Types have such a function?

P.S.
Regarding https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
It would be nice if the arguments were ordered/numbered list instead of unordered/bullet list

Thanks for the help.

#912137

Yes, you can specific the post_id parameter in Types function "types_render_field()", for example:

types_render_field('my-field-slug', array('post_id' => '123')); 

For ordered/numbered list issue, I will forward it to our editor as a request.

#913305
Image 2018-06-13 at 11.14.29 PM.jpg

Just what I needed. Thank you.

I am still a bit unclear how this is documented at https://toolset.com/documentation/customizing-sites-using-php/functions/#textfield though. Guess I'm just not following along.

Anyway, due to the bug reported at https://toolset.com/forums/topic/output-repeater-fields-in-their-drag-and-drop-order-in-wp-admin-edit-screen/#post-908851, I ended up having to extend the function's arguments so I could get to the $orderby parameter (see attached screenshot). So please do fix that.

Thanks for the help!

#918117

I saw a version update come through but the changelog was vague, and I couldn't find any changelog on your site. Was this bug fixed in this latest update?