Recurring scheduled task help

You have to schedule your event in a hook, for example in after_setup_theme or wp actions: add_filter(‘cron_schedules’,’my_cron_definer’); function my_cron_definer($schedules){ $schedules[‘twomin’] = array( ‘interval’=> 120, ‘display’=> __(‘Once Every 2 Minutes’) ); return $schedules; } add_action(‘my_periodic_action’,’my_periodic_function’); function my_periodic_function(){ mail(’[email protected]’,’Test!’, ‘Test Message’); } add_action( ‘wp’, ‘wpse8170_setup_events’ ); // or add_action( ‘after_setup_theme’, ‘wpse8170_setup_events’ ); function wpse8170_setup_events() { if ( … Read more

run a cron task without obstructing page load?

Cron tasks don’t directly affect page load besides the 0.01s timeout (of course, they do affect server load, so they can impact page load indirectly). My hunch is that your PHP config is the issue. The cron tasks run like any other web request, and they’re subject to PHP’s max_execution_time INI setting. If this is … Read more

When does next Cron Job run (time from now)?

Edit: wp_next_scheduled() returns the timestamp of the next scheduled job of a specified wp-cron job-arguments pair. Please note that this differs slightly in functionality to the answer below, in that you have to provide the arguments passed to cron job’s callback (if it has any). The original answer would provide the time of the next … Read more

wp-cron.php – How are WP’s Cron transients removed?

Transients expire on their own. No need to unset them. And to call wp-cron manually is simple. Just define DISABLE_WP_CRON to true in the wp-config file to disable the normal cron spawning process. Then make your cron system hit wp-cron.php manually every so often to process pending jobs. There is no other special trick that … Read more

Wp_Schedule_Event every day at specific time

WP Cron runs, when somebody visits your website. Thus if nobody visits, the cron never runs. Now there are 2 solutions: Disable WP Cron, use a real cron job and customize it. https://support.hostgator.com/articles/specialized-help/technical/wordpress/how-to-replace-wordpress-cron-with-a-real-cron-job Use a custom interval in wp_schedule_event(): function myprefix_custom_cron_schedule( $schedules ) { $schedules[‘every_six_hours’] = array( ‘interval’ => 21600, // Every 6 hours ‘display’ … Read more