Wordpress cron wp_schedule_single_event – action not always working Wordpress cron wp_schedule_single_event – action not always working wordpress wordpress

Wordpress cron wp_schedule_single_event – action not always working


From the codex:

Note that scheduling an event to occur before 10 minutes after an existing event of the same name will be ignored, unless you pass unique values for $args to each scheduled event.

If your custom hook is only working some of the time, then this might be an avenue to look at. If you require the hook to be handled immediately, then it might be prudent to look at giving a hook a unique name, or passing unique values to the hook.

If you do not need your job to execute immediately, then you could look at utilising wp_next_scheduled() to determine when the job will next run, and set a job to run after the next scheduled job.

It's also worth noting that if this task is something which seems to have consistent logic behind it (as seems to be the case) - why not store the job information in to the database and run a cron job every 5-10 minutes to pick up any new jobs from the database and handle them as such? This would avoid needing to deal with the behaviour of wp_schedule_single_event().


According to the official documentation on this instance,

Scheduling an event to occur within 10 minutes of an existing event with the same action hook will be ignored unless you pass unique $args values for each scheduled event. which you have stated tht you did but maybe a double check will help.

It is dependent on when a user visits the site so the action will trigger when someone visits your WordPress site if the scheduled time has passed.

Documentation also says you could use wp_next_scheduled() to prevent duplicate events and use wp_schedule_event() to schedule a recurring event.

The schedule might return true in certain instances where it run but was ignored. so it did run but it was ignored.

I would suggest a detailed log of everything that is sent and received so you can see for yourself if what is occuring is same as what you are confident on.

here are a few links with similar issues and documentation you could look at.

I hope this helps. if not, lets figure it out together.


From Wordpress Document:

WP-Cron works by checking, on every page load, a list of scheduledtasks to see what needs to be run. Any tasks due to run will be calledduring that page load.

WP-Cron does not run constantly as the system cron does; it is onlytriggered on page load.

Scheduling errors could occur if you schedulea task for 2:00PM and no page loads occur until 5:00PM.

I think your cron event may be missed because there is no page loads occur the scheduled time.

Here is a solution for your problem:Hooking WP-Cron Into the System Task Scheduler

As previously mentioned, WP-Cron does not run continuously, which canbe an issue if there are critical tasks that must run on time. Thereis an easy solution for this. Simply set up your system’s taskscheduler to run on the intervals you desire (or at the specific timeneeded). The easiest solution is to use a tool to make a web requestto the wp-cron.php file...