I am using wp_schedule_event
to hourly insert items from an rss news feed into my client's blog. Here is how I am setting it up in my functions.php:
add_action('init', function(){
$timescheduled = wp_next_scheduled('update_feed');
wp_unschedule_event($timescheduled, 'update_feed');
if (!wp_next_scheduled('update_feed'))
wp_schedule_event(time(), 'hourly', 'update_feed');
});
add_action('update_feed', 'update_fashion_news');
/* rest of the code for updaring feed goes here */
So first I unschedule it and then schedule the event. Now this seems to work some days and other times it doesn't. Is the unscheduling part necessary? Am I doing this right? What I want to know is:
- Am I using my function calls in the right order?
- Are the schedule and unschedule calls cancelling each other out?
Here is the full code in a gist if you want to see it: https://gist.github.com/3984658