Support

Account

Home Forums Add-ons Repeater Field Delete repeater`s sub_field after expired date Reply To: Delete repeater`s sub_field after expired date

  • To do this you need to use a CRON that:

    1. Queries all the posts
    2. Loops over the posts
    3. Loops over the repeater on each post (in reverse – SEE NOTE)
    4. Checks the date in each row
    5. Deletes expired rows using delete_row()

    Notes, you must delete the rows in revers order and you cannot use an have_rows loop to loop over the rows. The reason is this, lets say that you delete row 2, row 3 then becomes row 2 and the next iteration of the loop will look at row 3, which was row 4 before the deletion and the loop skips what was row 3 because it is now row 2.

    
    $repeater = get_field('repeater_name');
    // $repeater is an array of rows
    $count = count($repeater);
    for ($row=$count; $row>0; $row--) {
      if (//DATE EXPIRED//) {
        delete_row('repeater_name', $row);
      }
    }