How to delete an expired event by time

How to delete an expired event by time

In Order to display an event as Expired after a specific date and time, you need to add the following code to your theme functions.php file.

  1. Open your child theme,
  2. Add the code into the funtions.php file.
/* Event Expire by time */
function my_cron_schedules($schedules){
      if(!isset($schedules["5min"])){
        $schedules["5min"] = array( 'interval' => 560, 'display' => __('Once every 5 minutes'));    }
    }
    return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');
function schedule_my_cron($args){
wp_schedule_event(time(), '5min', 'my_schedule_hook');
}








  1. Next, create one field with the field type “Time” in the field editor at the admin panel.
  2. This would be visible on the event submission form, from where you can mention the time at which the event must expire.