cron job with WordPress

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

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.