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

  • add_filter('acf/load_value/name=start_date', '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 date
      $now = date("Ymd");
    
      // 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 = date("Ymd", strtotime(get_sub_field('start_date')));
        if ($start > $now) {
          $new_value[] = $row;
        }
      }
      return $new_value;
    }

    Look at this code. Can you figure out what is wrong with it.

    The fields look like this in admin

    ScreenShot