cron job in wordpress
snippet in php

cron job in wordpress

user943

register_activation_hook(__FILE__, 'my_activation');
 
function my_activation() {
    if (! wp_next_scheduled ( 'my_hourly_event' )) {
    wp_schedule_event(time(), 'hourly', 'my_hourly_event');
    }
}
 
add_action('my_hourly_event', 'do_this_hourly');
 
function do_this_hourly() {
    // do something every hour
}