By default, wp_schedule_event lets you choose a recurrence interval of ‘hourly’, ‘twicedaily’, or ‘daily’ for WP Cron jobs. Here, I show you how to add a custom recurrence interval of 3 minutes.
You may want to run a WP Cron job every 3 minutes, or so, for testing purposes. To add an interval of 3 minutes to the WP Cron schedules, use this:
function isa_add_every_three_minutes( $schedules ) {
$schedules['every_three_minutes'] = array(
'interval' => 180,
'display' => __( 'Every 3 Minutes', 'textdomain' )
);
return $schedules;
}
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
Now, you can use ‘every_three_minutes’ as the recurrence parameter when you use wp_schedule_event:
wp_schedule_event( time(), 'every_three_minutes', 'your_cron_function' );
You may want to run a WP Cron job every 3 minutes, or so, for testing purposes. To add an interval of 3 minutes to the WP Cron schedules, use this:
function isa_add_every_three_minutes( $schedules ) {
$schedules['every_three_minutes'] = array(
'interval' => 180,
'display' => __( 'Every 3 Minutes', 'textdomain' )
);
return $schedules;
}
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
Now, you can use ‘every_three_minutes’ as the recurrence parameter when you use wp_schedule_event:
wp_schedule_event( time(), 'every_three_minutes', 'your_cron_function' );
No comments:
Post a Comment