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

admin2025-06-05  3

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 );
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749077725a316168.html

最新回复(0)