Use cron to schedule events in your blog

WordPress has the ability to schedule event using built in cron. So you can use this to schedule events on your blog. In this sample an email is sent out hourly to specified address however you could schedule nearly anything.

 

 

if (!wp_next_scheduled('do_hook')) {
wp_schedule_event( time(), 'hourly', 'my_task_hook' );
}
add_action( 'do_hook', 'do_function' );
function do_function() {
wp_mail('you@wpsnipp.com', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.');
}

Be Sociable, Share!

Leave a comment