简体   繁体   中英

The “next run” in wp crontrol plug in is not working

I want to create a function which the function run in every 3 minute.

I use plugin wp-crontrol to create a cron job event.

I searched in Google and Stackoverflow, and the code in function.php is

// Add a new interval of 180 seconds
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
function isa_add_every_three_minutes( $schedules ) {
    $schedules['every_three_minutes'] = array(
            'interval'  => 180,
            'display'   => __( 'Every 3 Minutes', 'textdomain' )
    );
    return $schedules;
}

// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'isa_add_every_three_minutes' ) ) {
    wp_schedule_event( time(), 'every_three_minutes', 'isa_add_every_three_minutes' );
}

// Hook into that action that'll fire every three minutes
add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' );
function every_three_minutes_event_func() {
    // The code run update in every 3 minutes
    $update= get_field('ls_home_number_candidates');
    $updatePlusOne= $update++;
    update_post_meta(56, 'ls_home_number_candidates', $updatePlusOne);
}
?>

Then in my WP-Cron Events appears the new event called isa_add_every_three_minutes

But the event does not run. If I press "Run now", it's will appear a announce like "Successfully executed the cron event isa_add_every_three_minutes."

But it's not work and the field Next Run is always "now" 在此处输入图片说明

Please help. Thank you

The function isa_add_every_three_minutes in your code is just to get the custom schedules you set, it's not related to the cron name. Your add_action should have the cron name, and the cron function you want to execute, and then you need to call it, so something like:

// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'my_cron' ) ) {
    wp_schedule_event( time(), 'every_three_minutes', 'my_cron' );
}

// Hook into that action that'll fire every three minutes
add_action( 'my_cron', 'every_three_minutes_event_func' );

Everything else looks fine on the surface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM