Using WP-Cron in a theme, can it be done? I can’t make it work
-
As far as I can tell this should be all the code I need, but I can’t make it work
<?php // I don't want to be waiting around for things to change function more_cron_reccurences() { return array('minutely' => array('interval' => 60, 'display' => 'Once Minutely')); } add_filter('cron_schedules', 'more_cron_reccurences'); //the actual cron magic if (!wp_next_scheduled('some_hook')) { wp_schedule_event( time(), 'minutely', 'some_hook' ); } // wp_clear_scheduled_hook('some_hook'); add_action('some_hook', 'some_action'); function some_action(){ $current = get_option('how_long'); if (isset($current)) { $new = $current + 1; update_option('how_long', $new); } else { add_option('how_long', 0); } } ?> <div class="notice"> Should change in <?php echo wp_next_scheduled('some_hook')-time() ?> seconds.<br /> It's been <?php echo get_option('how_long') ?> times now. <br /> Next scheduled for: <?php echo date( get_option('time_format'), wp_next_scheduled('some_hook')) ?> </div>
The function updates the option correctly when fired on its own, and the timer does seem to count down, but the timer never actually fires the function.
All I can think is that it’s not actually possible for a cron to call a function in a theme… this would really aggravate me. Anyone have some good insight? I found the highly recommend post by Slaven. But I can’t find anything on how a cron might be different when working in a template.
- The topic ‘Using WP-Cron in a theme, can it be done? I can’t make it work’ is closed to new replies.