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( '****@******', 'Hourly E-mail from WP Cron', 'This message was sent on ' . $time );
}
I added this code on a form submission:
if ( !wp_next_scheduled('mail_cron_job') ) {
wp_schedule_event( time(), 'hourly', 'mail_cron_job');
}
The form data is submitting OK, but the cron job won't start. No error reports. Anything I'm missing?
you need to use an action hook to tie the event and function together.
You can add that right after the function.