Support

Account

Home Forums Add-ons Repeater Field Delete repeater row programmatically Reply To: Delete repeater row programmatically

  • 
    if (have_rows('repeater_field', $post_id)) {
      $new_repeater = array();
      while (have_rows('repeater_field', $post_id)) {
        the_row;
        // perform check
        // will depend on what you're checking for
        if (get_sub_field('the_sub_field_to_check') == $some_value) {
          // the value is one you want to save
          $new_repeater[] = array(
            'sub_field_1_name' => get_sub_field('sub_field_1_name'),
            'sub_field_2_name' => get_sub_field('sub_field_2_name'),
            'sub_field_3_name' => get_sub_field('sub_field_3_name'),
          );
        }  // end if check field
      } // end while have rows
      update_field('repeater_field', $new_repeater, $post_id);
    } // end if have rows