Support

Account

Home Forums Backend Issues (wp-admin) Get old value from a repeater in acf/update_value filter

Solved

Get old value from a repeater in acf/update_value filter

  • Hello I try to retrieve the old value from the database from a row in a repeater (same case for flexible)

    When i try with

    
    add_filter('acf/update_value', function($value, $post_id, $field, $original) {
      $old_value = acf_get_metadata($post_id, $field['name']);
      return $value;
    }, 10, 4);
    

    The value is ok, but not when i make reorder before the save.
    Or when i insert a new row before the last row.

    I’ve saw the name in a repeater field look like test_0_field but when we make a reorder the index change, so, i can’t retrieve the “good” value from the database.

    Anyone can help me ?

    Thanks !

  • If the order can change and the values in the field can change then there isn’t any way to match up the old rows with the new rows. In order to do this one of the values in the row would need to be unique and unchanged. Then you would need to loop over both the old value and the new value to find the right row.

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

The topic ‘Get old value from a repeater in acf/update_value filter’ is closed to new replies.