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!
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.