Answers for "wordpress cron daily"

PHP
3

cron job in wordpress

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
}
Posted by: Guest on October-08-2020
1

wp_schedule_event

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

register_deactivation_hook( __FILE__, 'my_deactivation' );
 
function my_deactivation() {
    wp_clear_scheduled_hook( 'my_hourly_event' );
}
Posted by: Guest on November-25-2020

Browse Popular Code Answers by Language