I’m trying to update a repeater field value using update_sub_field() in a custom plugin. I create the post and then updated the fields. It works great with normal fields e.g. update_field, however i’m having trouble adding rows to a repeater.
My repeater is called video_urls and has a text field called url.
Which looks like: ["video_urls",1,"url"], https://www.my-video-url.com, 414
414 is a valid post that I can view, but the URL’s not being updated. What am I missing here, i’ve followed the documentation: update_sub_field( array('repeater', 1, 'caption'), 'This caption is for the first row of the repeater!' );
If you know all of the values then it is easier to update the repeater rather than each sub field.
You may also be running into an issue with using field names VS field keys. When updating ACF fields when they do not already exist in the DB you need to use the field key.
To update a repeater in one go.
// making up field keys
// you need to get the correct ones for your fields
// construct an array for the repeater
$value = array(
// one nested array for each row
// field key => value pairs
'field_123456' => 'value',
'field_234567' => 'value',
update_field('field_987654', $value, $post_id);