1

I have a custom schedule defined for a cron job to be triggered. This is how my code looks:

<?php
//wp-config
define('DISABLE_WP_CRON', true);

//Plugin file
register_activation_hook( '__FILE__', 'activate' );

function activate() {
    if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
        wp_schedule_event( time(), 'everyminute', 'my_hourly_event' );
    }
}

add_filter( 'cron_schedules', 'add_cron_schedule' );

function add_cron_schedule( $schedules ) {
    $period = get_option( 'my_period', true );
    $schedules['everyminute'] = array(
        'interval' => MINUTE_IN_SECONDS * $period,
        'display' => __('My Schedule')
    );

    return $schedules;
}

add_action( 'my_hourly_event',  'cron_data_update' );

function cron_data_update() {
    //THIS NEVER RUNS!
    update_option( 'cron-check', 'Ran', 'no' );
}

This is the Linux cron that triggers it:

*/2 * * * * wget -q -O – http://somedomain.com/wp-cron.php?doing_wp_cron

Besides that, I don't see my event being listed in the gui:

enter image description here

The calls are never done. I cannot see that option in the database! Any ideas why it doesn't work?

  • 1
    You disabled the wp_cron than how it will work. – Kvvaradha Dec 2 '15 at 8:52
  • The tutorials I followed say that you have to disable it from wp-config. I am using a Linux cron job to trigger cron. – Rutwick Gangurde Dec 2 '15 at 9:17
  • There are two options. One is to disable so cron and use your server cron manager. Second using wp-cron. But you mixed two things – Kvvaradha Dec 2 '15 at 9:30
  • Remove the disable option and check it again. Than post your comment – Kvvaradha Dec 2 '15 at 9:39
  • If I am using a server to trigger the cron, then I have to disable it. Hold on, I'll post the cron job. – Rutwick Gangurde Dec 2 '15 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.