Home › Forums › Add-ons › Repeater Field › Update field in repeated field within group
Hello!,
I have been playing with this for a while without any results and have not found any answer for my problem yet :(. So here I come… kindly asking for a help.
I have this ACF structure:
Group -> basic_equipement
basic_equipement consist of repeated field and a title
repeated field cotains only text field.
As follows:
Groupd —->
–> title
–> repeater
–>text
I am creating a new post programmatically and adding the values to the ACF. For the non nested field I figured it out I use: update_field("id_ponuky", $details["Id"], $post_id);
I trigger my function to update the fields when my custom post type is saved.
In the repeated field and a text field within I have created a default values.
Now I want to add value to the nested nested text field. I can run command
if( have_rows('my_group') ):
this work fine
However I cannot go deeper and If I check for my nested repeater it does not exist.
I run throught the documentation and looked at a few answears but cannot figure this out. How to update the text in the repeater in the group after the post is created programatically.
Thanks for help
The first thing that you need to do is use field keys when updating acf field values for a post that has been inserted that does not already have values. There is a short explanation of this in the documentation.
When updating a group field or a repeater field you need to use the correct structure for the array. In your case you would update the group field with an array containing all of the sub fields that you want to update.
// let's assume that the field key of the group is field_GGGGGGG
$group_key = 'field_GGGGGGG';
$value = array(
// the value off a group is an array
// consisting of "field key" => "sub field value" pairs
// assume field_TTTTTTT is a text field
'field_field_TTTTTTT' => 'value of text field',
// assume that field_RRRRRRR is a repeater
'field_RRRRRRR' => array(
// a repeater value is an array
// each nested array is a row in the repeater
array(
// each element of the row contains
// "sub field key" => "sub field value" pairs
'field_1111111' => 'sub field 1 value'
'field_2222222' => 'sub field 2 value'
// etc....
)
),
);
update_field($group_key, $value, $post_id);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.