'ACF: Update a sub field inside a group field nested inside another group field

I have a frontend form for creating a CPT that takes in various details supposed to update the ACF fields associated with that CPT. On form submission, the CPT gets created and the simple ACF text, number etc fields get saved as well. But I am unable to update the sub_fields nested deep inside a group field. This is the structure of my main ACF Field group:

'Working hours' (field_61f453c010074 - Type: Group)

   a. 'Monday' Group Field (field_61f4570e89281 - Type: Group)
       * 'Am' Sub Field #1 (field_61f4573589282- Type: Number)
       * 'Pm' Sub Field #2 (field_61f4574589283- Type: Number)

   b. 'Tuesday' Group Field (field_61f7a30ffbcf0- Type: Group)
       * 'Am' Sub Field #1 (field_61f7a30ffbcf1- Type: Number)
       * 'Pm' Sub Field #2 (field_61f7a30ffbcf2- Type: Number)

and it goes on like that till Sunday. I have tried various approaches but to no avail. And there are no errors generated in the process.

My code demo for updating the 'Am' field of Monday:

if( have_rows('field_61f453c010074') ): while ( have_rows('field_61f453c010074') ) : the_row(); 

    if( have_rows('field_61f4570e89281') ): while ( have_rows('field_61f4570e89281') ) : the_row();       

        update_sub_field('field_61f4573589282', $_POST['am']);

    endwhile; endif;

endwhile; endif;

I also tried this:

$value = array(
    array(
        "field_61f4570e89281"   => array(                
            "field_61f4573589282"   => $_POST['am'],
            "field_61f4574589283"   => $_POST['pm']
        )

);
update_field( 'field_61f453c010074', $value, $post_id  );

Please help me. What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source