Home › Forums › ACF PRO › update_sub_field › Reply To: update_sub_field
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.