wp_schedule_event
($timestamp, $recurrence, $hook, $args) function will help you setup Cron Jobs in your WordPress blog. Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed.
Function Reference:
<?php wp_schedule_event($timestamp, $recurrence, $hook, $args); ?>
Parameters
- $timestamp
- (integer) (required) The first time that you want the event to occur. This must be in a UNIX timestamp format. WP cron uses UTC/GMT time, not local time. Use time(), which is always GMT in WordPress. (current_time( ‘timestamp’ ) is local time in WordPress.)
- Default: None
- $recurrence
- (string) (required) How often the event should reoccur. Valid values are below. You can create custom intervals using the cron_schedules filter in wp_get_schedules().
- hourly
- twicedaily
- daily
- Default: None
- $hook
- (string) (required) The name of an action hook to execute.
- Default: None
- $args
- (array) (optional) Arguments to pass to the hook function(s).
- Default: None
Sample:
if (!wp_next_scheduled('crunchify_task_hook')) { wp_schedule_event( time(), 'twicedaily', 'my_task_hook' ); } add_action( 'crunchify_task_hook', 'crunchify_task_function' ); function crunchify_task_function() { wp_mail('you@example.com', 'Crunchify Test Email', 'Hello, this is a test automatically scheduled email from WordPress.'); }