How to run WordPress wp_cron every 10 minutes

While developing a WordPress plugin which was relying on wp_cron I had to debug function that was called with the wp_cron. There was a need to run the cron every few minutes. Here is the solution:

Add following code to your plugin

add_filter('cron_schedules', 'new_interval');

// add once 10 minute interval to wp schedules
function new_interval($interval) {

    $interval['minutes_10'] = array('interval' => 10*60, 'display' => 'Once 10 minutes');

    return $interval;
}

Now you can use your time interval in wp_schedule_event

function InitiateMyCron() {
    if (!wp_next_scheduled('MyCronEvent')) {
        wp_schedule_event(time(), 'minutes_10', 'MyCronAction');
    }
}

Finally the function called by wp_cron

function MyCronAction() {
    //do my cron
}

3 thoughts on “How to run WordPress wp_cron every 10 minutes

  1. I’ve added the first code in my templates functions.php and used the “minutes_10” interval in an existing function instead of “hourly”. Is this a good way of implementing your code? I still have to wait a few minutes to see if it will run the cron..

  2. Hi Joseph

    You should make a and in your plugin, function MyCronAction is what is going to run every ten minutes, of course you need to actually have visitors on site as cron is triggered (checked) each time page is reloaded

  3. Pingback: 10+1 WordPress Cron Articles – Introduction, Tips, Tutorials | DesignFloat Blog

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.