Initialize WordPress environment to use in a real cron script
You can use real cron to trigger WP cron – by fetching wp-cron.php file from root (snippet from quick google search). That will take care of environment and everything.
You can use real cron to trigger WP cron – by fetching wp-cron.php file from root (snippet from quick google search). That will take care of environment and everything.
As you’ve noted, cron jobs are only fired when someone visits your website. WordPress checks if they are any events that have been scheduled before ‘now’ that have not yet occurred – and runs them. Importantly with events that are recur according to a regularly pattern (say hourly) – their occurrence is relative not absolute. … Read more
This is only a partial answer. You can use Cron View to see what crons are still active on your blog. If you find some crons that shouldn’t be there then maybe my answer here will help you remove that cron: Cron jobs for deactivated plugins
No, the WP-Cron tasks run asynchronously from the viewing user. They should not see any delay. Although if your task takes more than a minute, it may never finish since most hosts are setup to kill PHP processes after 30 seconds.
Whenever you do get_posts or WP_Query or anything like that, it’s important to remember that the code is actually getting all of the Posts at once, and loading them from the database into memory. If you run out of memory, then your process will simply die with an error. Attempting to get very large numbers … Read more
This is a typical example of an X-Y problem. Your cron is fine. Your logic not so. You have a function that hooks into save_posts and you think that passing the array $update = array( ‘ID’ => get_the_ID() ) will trigger the action and so your post will update the taxonomy. That’s incorrect, unfortunately. Passing … Read more
It looks for me that you are adding this event only when there is no such event ‘send_email_alerts_hook’ scheduled yet. Try something like this and let me know if it workded. function shedule_email_alerts() { if ( !wp_next_scheduled( ‘send_email_alerts_hook’ ) ) { wp_schedule_event(time(), ‘daily’, ‘send_email_alerts_hook’); } else { wp_reschedule_event(time(), ‘daily’, ‘send_email_alerts_hook’); } } The thing is … Read more
Check out wp_cron and the cron_schedules filter. There are lots of good tutorials out there like this one from WPTuts or this one from Viper007Bond.
As described in wp_schedule_event first parameter is $timestamp – the first time that you want the event to occur. So just add interval to $timestamp. I think it should be like wp_schedule_event( time() + $delay, ‘interval1’, ‘my_cron_hook’ ); And set $delay as miliseconds before hook starts.
Or, you could use WP-CLI which was developed for scenarios like these. After a short installation like this $ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp You can run your scheduled tasks like so $ wp cron event run –due-now –path=/var/www/mywebsite.com/ or via crontab (every 5mins) */5 * * * … Read more