Add row to nested repeater in Wordpress Advanced Custom Fields PRO
<p>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 <code>update_field()</code> or <code>update_sub_field()</code> function.</p>

<p>The <code>update_field()</code> function works great for first-level repeater rows, i.e.:</p>

<pre><code>update_field( $field_key, $value, $postID );
</code></pre>

<p>but I am uncertain about how to use this for nested repeaters.  This is the ACF Fields structure:</p>

<pre><code>CUSTOM POST TYPE
    Repeater Field - "Media"
         Repeater Field - "Notes"
</code></pre>

<p>So, here is the code I am attempting:</p>

<pre><code>$field_key = "field_xxxxxxxxxxxxx"; //NOTES FIELD KEY
$value = get_field($field_key, 12); //GET FIELDS OF POST ID 12, NOTES
$value[] = array("note" =&gt; "Here is a new note");
update_field( $field_key, $value, 12 );
</code></pre>

<p>But this does nothing.  There is no way to determine <em>WHICH</em> "Media" repeater I am wishing to add a "note" to.</p>

<p>I can successfully "update" the nested repeater field using <a href="https://www.advancedcustomfields.com/resources/update_sub_field/" rel="nofollow">update_sub_field()</a> 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.</p>

<pre><code>update_sub_field( array('media', 1, 'notes', 2, 'note'), 'Here is a new note!', $postID );
</code></pre>

<p>What can I do to add rows to a nested repeater whether there is a row already or not?</p>