$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp_get_schedule and wp_next_scheduled don't find my scheduled wp-cron job|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp_get_schedule and wp_next_scheduled don't find my scheduled wp-cron job

matteradmin11PV0评论

I have tried the following two approaches, each resulting that the cronjob gets added over and over again, until I remove the code. I literally had it scheduled hundreds of times...

if(!wp_next_scheduled('send_order_surveys')){
    wp_schedule_event(time(), '30min', 'send_order_surveys');
}

if(!wp_get_schedule('send_order_surveys')){
   wp_schedule_event(time(), '30min', 'send_order_surveys');
}

What am I doing wrong?

I have tried the following two approaches, each resulting that the cronjob gets added over and over again, until I remove the code. I literally had it scheduled hundreds of times...

if(!wp_next_scheduled('send_order_surveys')){
    wp_schedule_event(time(), '30min', 'send_order_surveys');
}

if(!wp_get_schedule('send_order_surveys')){
   wp_schedule_event(time(), '30min', 'send_order_surveys');
}

What am I doing wrong?

Share Improve this question asked Dec 21, 2018 at 14:19 Johano FierraJohano Fierra 8256 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 7

Well, I found the answer in the actual documentation: https://developer.wordpress/reference/functions/wp_next_scheduled/

in form of a comment by "ub3rst4r":

Note the $args parameter! Not specifying the $args parameter in wp_next_scheduled but having $args for wp_schedule_event will cause many events to be scheduled (instead of just one).

Bad Example:

if ( ! wp_next_scheduled( 'myevent' ) ) { // This will always be false
    wp_schedule_event( time(), 'daily', 'myevent', array( false ) );
}

Good Example:

$args = array( false );
if ( ! wp_next_scheduled( 'myevent', $args ) ) {
    wp_schedule_event( time(), 'daily', 'myevent', $args );
}
Post a comment

comment list (0)

  1. No comments so far