Support

Account

Home Forums ACF PRO get_field after update_sub_field gets old values

Solved

get_field after update_sub_field gets old values

  • Hey there,

    I have an update_sub_field inside a foreach after which, I do a get_field of the repeater right after the update, but it still has the old values even though the update_sub_field did indeed update everything correctly.

    Not sure why ACF get_field is still getting old values. Thanks for any help!

    E.g.

    $lists = get_field('lists', $post->ID); // repeater field
    
    foreach ($lists as $key => $list) {
        update_sub_field(array('lists', $key, 'field'), 0, $post->ID); // switch from '1' to '0'
    }
    
    $lists = get_field('lists', $post->ID);
    
    var_dump($lists);
    
    // outputs old values which is incorrect
  • Help, Hilfe, Upomoc! 🙂

    I did manage to find a temp. workaround for this issue by setting $list[ $key ]['field'] = 0 within the foreach and then updating the repeater i.e. update_field('lists', $lists, $post->ID) before retrieving it again. Not exactly an optimal solution though.

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

The topic ‘get_field after update_sub_field gets old values’ is closed to new replies.