Support

Account

Home Forums ACF PRO update_sub_field

Solving

update_sub_field

  • Hello,
    It does not work 🙁

    // field_54a99fb56076d is a group. Repeater
    // field_54a99f8f6076e HH:MM text in that group
    // field_54a9a00e6076f true / false in that group
    			
    update_sub_field( array( "field_54a99fb56076d",1,"field_54a99f8f6076e" ), "08:00", $post_id);
    
    update_sub_field( array( "field_54a99fb56076d",1,"field_54a99f8f6076f" ), true, $post_id );
    

    Something is wrong, but what ?

    Thanks.

  • I had similar problems and it seems that update_sub_field function is bit buggy at the moment. However, I managed to update existing repeater subfield with following code, it seems exactly like yours but it’s wrapped in have_rows() loop:

    
    // field_54d5f40bbbe1d = repeater
    // field_54e4513b63547 = subfield
    
    if( have_rows('field_54d5f40bbbe1d', $post_id) ):
        $row_index = 0;
        while ( have_rows('field_54d5f40bbbe1d', $post_id) ) : the_row();
        
            $row_index++;
            
            // just some generic conditional logic to update specific sub_field, in this case by 'name' sub_field
            if(get_sub_field('name') == $what_i_want_it_to_be){ 
                update_sub_field( array("field_54d5f40bbbe1d", $row_index, "field_54e4513b63547"), 'test', $post_id);
            }
            
        endwhile;
    endif;
    

    I think looping this through have_rows() shouldn’t have anything to do with updating sub field. Hope this helps.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘update_sub_field’ is closed to new replies.