I am running ACF PRO 5.3.9.2, but I think this pertains to any version with nested repeaters. I am hoping to add rows to a nested repeater (that is a repeater inside a repeater) using the update_field() or update_sub_field() function.
The update_field() function works great for first-level repeater rows, i.e.:
update_field( $field_key, $value, $postID );
but I am uncertain about how to use this for nested repeaters. This is the ACF Fields structure:
CUSTOM POST TYPE
Repeater Field - "Media"
Repeater Field - "Notes"
So, here is the code I am attempting:
$field_key = "field_xxxxxxxxxxxxx"; //NOTES FIELD KEY
$value = get_field($field_key, 12); //GET FIELDS OF POST ID 12, NOTES
$value[] = array("note" => "Here is a new note");
update_field( $field_key, $value, 12 );
But this does nothing. There is no way to determine WHICH "Media" repeater I am wishing to add a "note" to.
I can successfully "update" the nested repeater field using update_sub_field() like the code below IF and only IF there is a row in the nested repeater field, but it overwrites just the one row and cannot add to it. It also will not work if there isn't currently a row in the repeater.
update_sub_field( array('media', 1, 'notes', 2, 'note'), 'Here is a new note!', $postID );
What can I do to add rows to a nested repeater whether there is a row already or not?