I have made a WordPress cron job that should send out a mail each hour:
function mail_cron_job() {
$time = date( \'h:ia\', time() );
wp_mail( \'****@
Cron Job Schedule in wordpress
//Add Interval [ Day ]
function cron_add_daily($schedules)
{
// Adds once every minute to the existing schedules.
$schedules['daily'] = array('display' =>( 'Once Daily' ) );
return $schedules;
}
add_filter( 'cron_schedules', 'cron_add_daily' );
// create a scheduled event (if it does not exist already)
function cron_activation() {
if( !wp_next_scheduled( 'plugin_mailcronjob' ) ) {
wp_schedule_event(time(), 'daily', 'plugin_mailcronjob' );
}
}
// and make sure it's called whenever WordPress loads
add_action('init', 'crons_activation');
function repeat_function_daily()
{
/*
put code here what you want check daily
*/
}
// hook that function onto our scheduled event:
add_action ('plugin_mailcronjob', 'repeat_function_daily');
you need to use an action hook to tie the event and function together.
add_action( 'mail_cron_job', 'mail_cron_job' );
You can add that right after the function.