Tag Info

New answers tagged

1

WP cron tasks execute in completely separate process from page load. Nothing from the task's output will be ever seen by users. That's the purpose of them, to run scheduled task without interfering with site itself. If you want to output to the page periodically you will have to build it in other way. You could store the data (such as timestamps) in an ...


0

I would suggest looking at using transients for your data. Using transients would also take care of needing to use cron to update the data. Transients are an under utilised function of Wordpress and can save considerable loads on resources as sites get busier. Vee


0

Add timezone offset to your timestamp. $offset = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; return date_i18n( get_option( 'date_format' ), $ts + $offset ); or better; $tz = new DateTimeZone( get_option( 'timezone_string' ) ); $offset_for_that_time = timezone_offset_get ( $tz , new DateTime("@{$ts}") ); return date_i18n ( get_option( 'date_format' ), ...


0

As you mentioned, WordPress by default only runs the wp_cron when the WordPress site is visited. This of course will cause problems if you are needing to schedule some event reliably, and you aren't getting consistent traffic to your site. To resolve this, you can disable the default functionality of the wordpress cron by adding the following line to your ...


2

You shouldn't call wp_clear_scheduled_hook on every page load, because then you're always restarting your wp-cron shcedule, with your current setup. Additionally this call: wp_clear_scheduled_hook( 'le_do_this' ); doesn't make any difference, since le_do_this isn't a hook name in your setup. You could try for example this test plugin: <?php /** * ...


1

In wp-includes/default-filters.php we can find a callback registration: // WP Cron if ( !defined( 'DOING_CRON' ) ) add_action( 'init', 'wp_cron' ); If we go the function wp_cron() now, we see this: $schedules = wp_get_schedules(); foreach ( $crons as $timestamp => $cronhooks ) { if ( $timestamp > $gmt_time ) break; foreach ( (array) ...


1

I was having the same issue recently, until I followed an example from the Wordpress Codex which suggests using action hooks to run the function. I think if you add the following... add_action( 'recalculate_all_scores_hook', 'recalculate_all_scores' ); ...and amend the wp_schedule_event function to use the action hook name rather than the function ...



Top 50 recent answers are included