Home Forums ACF PRO update repeater field on acf/save_post Reply To: update repeater field on acf/save_post

  • Usually, when I’m doing something like this with repeater fields I don’t actually use ACF functions or try to work directly with the values in $_POST.

    Here’s an example of something I’d do, I do this because I know how ACF stores data and it’s just easier and faster to work with native WP functions for me.

    post_updating_callback($post_id) {
      $repeater = 'my_repeater'; // the field name of the repeater field
      $subfield1 = 'subfield_1'; // the field I want to get
      $subfield2 = 'subfield_2'; // the field I want to set
      // get the number of rows in the repeater
      $count = intval(get_post_meta($post_id, $repeater, true);
      // loop through the rows
      for (i=0; $i<$count; $i++) {
        $get_field = $repeater.'_'.$i.'_'.$subfield1;
        $set_field = $repeater.'_'.$i.'_'.$subfield2;
        $value = get_post_meta($post_id, $get_field, true);
        // do whatever I need to calculate the value to set
        // $new_value will hold the value to set
        update_post_meta($post_id, $set_field, $new_value);

    Hope this helps.