How to use the cron job with WordPress

In linux OS and windows OS cron jobs been used for backgroud tasks, many times you need to execute the some background tasks based on time. In wordpress creating the cron jobs is very easy. For creating the cronjob you can use the wp_schedule_event() event. You can run the cron based on time defined.

In linux and mac box adding cronjobs are different then using in wordpress. WordPress itself supports the adding cronjobs events or tasks. Here in this article I explained about using cron job with WordPress.

CRON job with WordPress

You can pass following parameters:
hourly
twicedaily
daily

<?php
add_action('wpapi_hourly_event', 'do_this_daily');

function wpapi_activation() {
    if ( !wp_next_scheduled( 'wpapi_hourly_event' ) ) {
        wp_schedule_event(time(), 'daily', 'wpapi_daily_event');
    }
}
add_action('wp', 'wpapi_activation');

function do_this_hourly() {
    // do something daily
}
?>
cron job with WordPress

cron job with WordPress

For more detailed information you can visit
http://codex.wordpress.org/Function_Reference/wp_schedule_event

Add a Comment

Your email address will not be published. Required fields are marked *