I'm not well verse with WP Cron, but I used them in one of my site knowledgeably. I set a custom query for every hour:
add_action( 'init', function () {
if( ! wp_next_scheduled( 'expire_cpt' ) ) {
wp_schedule_event( time(), 'hourly', 'expire_cpt' );
}
add_action( 'expire_cpt', 'pre_expire_the_offers' );
});
function pre_expire_the_offers() {
//...
}
Now our procedure to the function changed, and we thought to go for a daily schedule. So I set up the things this way:
add_action( 'init', function () {
//Used once to delete all the schedule
//wp_clear_scheduled_hook('expire_cpt');
//I assumed, by clearing, I no-longer need this
//$timestamp = wp_next_scheduled( 'expire_cpt' );
//wp_unschedule_event( $timestamp, 'expire_cpt' );
if( ! wp_next_scheduled( 'expire_cpt' ) ) {
//Need to run this at 24:00:00 everyday, not 24 hours from now
wp_schedule_event( time('00:00:00'), 'daily', 'expire_cpt' );
}
add_action( 'expire_cpt', 'pre_expire_the_offers' );
});
I'm doing this on local WAMP server in a Windows Machine. My Local PC time, as I got, echoing echo date( 'Y-m-d H:i:s', current_time( 'timestamp' ) )
, is 2016-04-11 17:18:58.
A six hour difference can be the GMT and my Time Zone (+6) - that's reasonable.
But the problem is with the Next Scheduled Time.
I'm using:
- Debug Bar Cron - WordPress Plugin, and then tried
- Advanced Cron Manager - debug & control - WordPress Plugin
for debugging Cron jobs.
Debug Bar Cron is showing the current time is: 11:52:54, while my timestamp is showing: 17:52:52. Problem is, the Next Occurrence time is not 00:00:00, but
2016-04-12 11:33:56
1460460836
24 hours
ACM is showing:
In 24 hours
12.04.2016 17:33:56
How can I re-schedule my query/function on a specific time, everyday (editing my current schedule)?