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.
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!
Are you an advanced @wp_acf user eager to learn Headless #WordPress?— WP Engine Builders (@wpebuilders) December 5, 2022
This upcoming webinar hosted by @J_Everhart383 was made for you.
👉 Register now: https://t.co/NrzWJZbdoN
Building Your First Headless WordPress Project with ACF + @wpgraphql 🎉 pic.twitter.com/ymyuPqkY2F
© 2022 Advanced Custom Fields.