您完全可以使用wp\\u cron指定时间:
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\' );
//define a timestamp to run this the first time. 4:20 is as good a time as any.
$timestamp = strtotime( \'2013-12-14 16:20:00\' );
//set a recurrence interval - WP has three default intervals: hourly, daily & twicedaily
$recurrence = \'daily\';
//define the hook to run
$hook = \'my_scheduled_event\'
//you can pass arguments to the hooked function if need be. this parameter is optional:
$args = null;
//the following will run your function starting at the time defined by timestamp and recurring every $recurrence
wp_schedule_event( $timestamp, $recurrence, $hook, $args );
这是一个过于简化的示例。需要进行某种类型的检查,这样您就不会得到一船排好的钩子,但它应该会让您知道如何在特定时间进行设置。此外,需要了解的是,wp\\u cron是由页面加载触发的,因此如果您的站点没有大量的流量,那么该功能将无法准确地在定义的时间启动。不过,有一些解决办法。