wp_schedule_event() on specific time, daily

time() only returns current time, it doesn’t accept any inputs.

$time = time(); // works out to 2016-04-11T12:11:34+00:00

What you want is midnight tomorrow:

$tomorrow = strtotime( 'tomorrow' ); // works out to 2016-04-12T00:00:00+00:00

Note that these are PHP functions and they ignore WP timezone, since it resets PHP time zone to UTC. So if using these you are setting it to midnight in UTC time zone.

To get it right in WP is a mess (this might not work under some configurations that have no timezone_string set, see my post on DateTime in WP for more details):

$date = new DateTime( 'tomorrow', new DateTimeZone( get_option( 'timezone_string' ) ) );
// works out to 2016-04-12T00:00:00+03:00
$timestamp = $date->getTimestamp();

Note: WP Cron isn’t guaranteed to run at precise time since it is trigerred by visits to the site. I am not confident if recurrent runs will “stick” at midnight or will slowly slip from there, you might need to readjust periodically.

Leave a Comment