正如Fleuv所说,您可以使用wp\\u schedule\\u event()函数像这样执行代码
add_action(\'my_twfours_action\', \'my_twfours_action_fn\');
my_twfours_action_fn (){
//this code will execute every 24 hours
}
wp_schedule_event( time(), \'daily\', \'my_twfours_action\' ); //adding new cron schedule event
创建2分钟筛选器,然后安排cron jo如下
function my_two_minutes_filter( $schedules ) {
$schedules[\'two_minutes\'] = array(
\'interval\' => 120,
\'display\' => __( \'Every 2 minutes\' ),
);
return $schedules;
}
add_filter( \'cron_schedules\', \'my_two_minutes_filter\' );
然后添加操作并安排事件,如
add_action(\'my_twominutes_call\', \'my_twominutes_call_fn\');
my_twominutes_call_fn(){
//this code will execute every 2 minutes
}
wp_schedule_event( time(), \'two_minutes\', \'my_twominutes_call\' ); //adding new cron schedule event
在此处阅读更多信息
wp_schedule_event();