Welcome to FindNerd. Today we are going to discuss the concept of cron in wordpress, how we can set up the cron in wordpress. We use the cron_schedules filter to set
the time intervak to schedule, ewp_send_email_cron_hook function to check the next available interval and schedule the event by using function wp_schedule_event.
Please have a look.
add_filter('cron_schedules','nerd_get_cron');
function nerd_get_cron( $schedules ) {
$schedules['nerd_auto_cron_every_minute'] = array(
'interval'=>60,
'display' => __('FindNerd Cron on every Minute')
);
return $schedules;
}
Above code used to set the time interval for cron.
if(!wp_next_scheduled('nerd_get_notification_cron_hook' ) ) {
wp_schedule_event(time(),'nerd_auto_cron_every_minute','nerd_get_notification_cron_hook');
}
Above code used to schedule the event for next available interval
add_action('nerd_get_notification_cron_hook', 'get_notification_cron' );
function get_notification_cron()
{
// notification code goes here
}
Above code used to add the action for the scheduled process. Wordpress cron will start when page will be refreshed.
0 Comment(s)