Sahil Jain
Sahil Jain

Reputation: 89

wp_schedule_event() not working

I want to schedule an event in Wordpress. Here is the simplest form that I've tried placing in the header to test, but it doesn't work:

add_action ( 'my_schedule_hook', 'testing_only' );


if ( !wp_next_scheduled( 'my_schedule_hook' ) ) {
    wp_schedule_event( time(1442233753), 'daily', 'my_schedule_hook' );
}   

function testing_only(){
    $wpdb->insert( 'wp_postmeta', array( 'meta_key' => 'test' , 'meta_value' => '001122' ) );           
}

Also, I've tried these two:

define('DISABLE_WP_CRON', true);  
define('ALTERNATE_WP_CRON', true); 

But those don't work, either.

Upvotes: 0

Views: 2595

Answers (1)

Ali Idrees
Ali Idrees

Reputation: 598

There's no need for define('ALTERNATE_WP_CRON', true);

You disabled WordPress to execute the crons upon site visitors by adding define('DISABLE_WP_CRON', true);

Anyway, you can navigate to www.yoursitename.com/wp-cron.php and it will trigger any scheduled crons that needs to run (i.e. their scheduled time has passed)

Upvotes: 1

Related Questions