Support

Account

Home Forums General Issues Delete all repeater rows? Reply To: Delete all repeater rows?

  • Hi @frazecolder ,

    You can achieve the same by updating the field using update_field as below.

    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