I’m trying to schedule event on hourly basis but it doesn’t work. Why, I can’t understand.
Here is a function that i use to schedule event.
add_action( 'scheduled_update_feeds', 'update_feeds', 10, 2 );
function scheduled_activation() {
wp_schedule_event( time(), 'everyhour', 'scheduled_update_feeds', array( 0, 'everyhour' ) );
}
register_activation_hook( __FILE__, 'scheduled_activation' );
Per my understandings this should activate on plugin activation and pass schedule event based on my settings.
When I use it without array args it works, but I need to use args to pass them my scheduled function.
And this is the function
function update_feeds($ids = false, $timing = false) {
do something
}
When i use it like this it works.
wp_schedule_event( time(), 'everyhour', 'scheduled_update_feeds' );
Even if I don’t use args in my update_feed function it doesn’t work either. The strange thing is that when I use single schedule it works.
like this
wp_schedule_single_event( time() + 10, 'scheduled_update_feeds', array($ids) );
So I don’t get it why it won’t work.
And I did defined ‘everyhour’ in my scheduled list.
add_filter( 'cron_schedules', 'my_schedule' );
$schedules['everyhour'] = array(
'interval' => 60,
'display' => __( 'Every hour', 'easy-video-grabber' )
);
I checked its existance with the Cron Schedules plugin and the schedule exists.
This is not a fix for your problem, but it might lead you in the right direction to solving the issue. I would suggest checking out this plugin to possibly help you find out what is going on:
WP Cron Control
It offers a quick view of cron jobs scheduled throughout your site. I recently used it to resolve a problem occurring when scheduled emails were not being sent out.
In the simplistic way. Register a filer, embed with action & use it. For quick example:
Register an event:
Execute functions:
*Please note that wp cron jobs are different than usual linux cron jobs. WordPress internally run thread on when user hit the website. If no hit on website in a day then there is not cron job executed, because cron job thread is not running.
For more information how cron jobs work in WP, check this quick reference guide
Thanks
I’ve had this problem before. What is happening (from the looks of it) is that you are setting up the action hook to be scheduled, but failing to make use of it.
e.g.
In addition to this, you would need something like:
wp_schedule_event sets up an action to be run, so in addition to a function to do things, you need to add an action to be carried out on the action tag specified.
I’d also recommend checking to see if it exists before adding it:
Finally, I’d recommend using less generic names, especially for your processing function. There are probably plenty of people out there that will create an update_feeds function.
Anywise, hope that helps.