I've found this code which is supposed to update a repeater field in ACF Wordpress. My repeater has 3 columns. I need to update only a certain field from one column in the repeater. How to do that with this code:
// save a repeater field value
$field_key = "field_3424324234";
$value = array(
array(
"sub_field_1" => "Foo",
"sub_field_2" => "Bar"
)
);
update_field( $field_key, $value, $post_id );
I need to say that I don't have a PRO license and I can't use update_sub_field().
I will answer my question bellow. I used a function a little different than update_field, called update_sub_field. For this to work you need to have ACF Pro 5+. Jordi Nebot answer helped me a bit, but in my case I needed to add some extra variable($post_id
). So here it is, hoping will help someone:
update_sub_field( array("repeater_field_key", $row+1, "repeater_sub_field_key"), $new_value, $post_id);
I added $row+1
because $row
number count starts from 1
, when $row
start position starts from 0
when looping through repeater. Hope it makes sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With