wp_schedule_event / cron_schedules – custom recurrence time not working in Plugin
WP-Cron doesn’t run in the admin scope – remove your if ( is_admin() ) condition.
WP-Cron doesn’t run in the admin scope – remove your if ( is_admin() ) condition.
Here’s how I would go about doing this: First create a file with a hash for the file name within your theme directory – this one is md5(‘foobar’): 3858f62230ac3c915f300c664312c63f.php Within that file would be something like this: //Use the file name as an API key of sorts $file = explode(‘.’, basename(__FILE__)); $key = $file[0]; //Trigger … Read more
I think I would write a wrapper function around custom fields, something like this: function get_post_transient( $post_ID, $meta_key, $update_function ) { $current_value = get_post_meta( $post_ID, $meta_key, true ); if ( is_array( $current_value ) && $current_value[‘expiration’] < date(‘U’) ) return $current_value[‘data’]; $new_value = call_user_function( $update_function, $post_ID ); update_post_meta( $post_ID, $meta_key, $new_value ); return $new_value[‘data’]; } and … Read more
WordPress lets you add custom cron schedules, which is normally what you’d want to do in this situation, in conjunction with wp_schedule_event(). But, they work based on intervals rather than specific dates/times. For instance, add_filter( ‘cron_schedules’, ‘addCustomCronIntervals’ ); function addCustomCronIntervals( $schedules ) { $schedules[ self::PREFIX . ‘debug’ ] = array( ‘interval’ => 60 * 2, … Read more
wp_cron is a PHP level system and so also only runs on page load. It does not run on clock time so you’d still need to reload the page to get the loop to run. Second, to get this working with wp_cron you’d need to pull all of your posts with _limited_dates_to set and loop … Read more
How wp-cron.php behaves depends on how you execute it. If you execute it by HTTP request with ‘doing_wp_cron’ in the GET string, it will check if another wp-cron process has set a lock and exit if it has. By default, this is how WordPress executes it. It is easily done in crontab like so: */10 … Read more
you can absolutely use wp_cron to specify a time: add_action( ‘my_scheduled_event’, ‘prefix_my_scheduled_event’ ); /** * On the scheduled action hook, run a function. */ function prefix_my_scheduled_event() { // do something } //going to use the strtotime function, so a good habit to get into is to set the PHP timezone to UTC default_timezone_set( ‘UTC’ ); … Read more
Almost, WP Cron jobs do not run at specific times, they are approximate, and all timestamps should be UTC, as WordPress always deals in UTC timestamps. If you want midnight PST, you’ll want to specify 8PM UTC. Also for example, your above code suggests midnight PST, but it may not run at midnight PST. If … Read more
This should be a comment, but I don’t have comment privelages 🙁 I had this exact problem not long ago, and felt stupid when I realised it was because I had set a password on the directory…
Maybe the problem happens because you don’t check if your hook is already scheduled. if ( !wp_next_scheduled( ‘first_hook’ ) ) { wp_schedule_event(time()+60, ‘daily’, ‘first_hook’); }