Home / admin / Use cron to schedule events in your blog
  • How to Use cron to schedule events in your blog

    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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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.');
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    schedule_event, add_action, _n, _e, wp_next_scheduled, wp_schedule_event, wp, wp_mail,