Skip Navigation

[Gelöst] Need help using PHP to output raw values in a repeatable field group

This support ticket is created vor 6 Jahren, 3 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Beda vor 6 Jahren, 3 Monaten.

Author
Artikel
#1097144

Hello,

I need to get access to the values of a repeatable field group called "Taxes" (rf-taxes). Each group has "Year" (rf-tax-year) and "Amount" (rf-tax-amount).

What is the php code that I would use get the values in some way that I can put them into an array or object? My end goal is to output XML for Zillow like this:

<Taxes>
<Tax>
<Year>2018</Year>
<Amount>1200</Amount>
</Tax>
<Tax>
<Year>2017</Year>
<Amount>1180</Amount>
</Tax>
</Taxes>

I have a php script that is crafting that but I have been having trouble just getting access to the values in the first place. Your help would be greatly appreciated!

#1097374

First, you would need to get the Post (Repeatable Field Groups are Posts).
So, each "group" of fields represents one Post that is associated to the Post where the Fields appear with a One To Many Relationship created by Types.

This means, if you, for example, are working on a Single Post, then you can get it's related Repeating Fields Groups by calling the Child posts of that post. This can be done with the Toolset Relationship API (toolset_get_related_posts()), if you need to do it programmatically, however usually you will use a View for this.
No Code: https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/
Code: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

The slug of the $relationship, in this case, is the slug of the Repeating Field Group as seen in Toolset > Fields > Edit (RFG)

This will return you none (if none) or one (if one) or many (if more) Repeating Field Group Posts.
Those Posts' meta fields are then the fields you actually saved in the RFG.
That means you can easily get them with get_post_meta() where the Post ID is the Post ID of the RFG above code returns.