Support

Account

Home Forums Front-end Issues Delete ACF repeater field entry from backend after date expiry Reply To: Delete ACF repeater field entry from backend after date expiry

  • I can give a generic example, but it would be highly dependent on how you are displaying date/time values and this code may not work.

    
    add_filter('acf/load_value/name=repeater_field_name', 'delete_old_courses_by_date');
    function delete_old_courses_by_date($rows, $post_id, $field) {
      if (!is_array($value) || !count($value)) {
        return $value;
      }
      // get the current timestamp
      $now = time();
    
      // set up a new array to hold the values we keep
      $new_value = array();
      foreach ($rows as $row) {
        // the php strtotime() function could fail depending on
        // the return format of the date/time fields
        // this requires a valid date/time format as documented here
        // http://php.net/manual/en/datetime.formats.php
        // if this does not work I probably won't be much help figuring
        // our how to covert your return value to something usable
        $start = strtotime($row['start_date']);
        $end = strtotime($row['end_date']);
        if ($start > $now || $end > $now) {
          $new_value[] = $row;
        }
      }
      return $new_value;
    }