I’ve been trying to figure out why i can’t update the value of a sub field like this. Hopefully someone can explain this for me. This is my current code for my acf/save_post hook in my functions.php file:
add_action('acf/save_post', 'custom_codeveld_acf_save_post', 20);
function custom_codeveld_acf_save_post( $post_id ) {
$the_post = get_post($post_id);
if( $the_post->post_type == 'post' ) {
//Repeater field
if( have_rows('codevelden', $post_id) ):
while( have_rows('codevelden', $post_id) ) : the_row();
//Group field
if( have_rows('codegroep', $post_id) ):
while( have_rows('codegroep', $post_id) ) :
the_row();
update_sub_field('codeveld', "Test");
endwhile;
endif;
endwhile;
endif;
}
}
After the first have_rows() loop you no longer need to supply the post ID
// post id not needed in sub loops
if( have_rows('codegroep') ):
while( have_rows('codegroep') ) :
Other than this the only reason I know of that the row cannot be update is that there are not rows to begin with and have_rows() is false. You cannot use have_rows() loops to update repeaters that have no values/rows.