2017-05-19 48 views
0

我在WP新的,我需要使用wp_schedule_event。 我這個代碼調度事件只有一次

add_action('my_func', 'my_func'); 
function myFunction() { 
    error_log("asd"); 
} 

function activateSchedule($recurrence) { 
    if(!wp_next_scheduled('my_func')) { 
    // Schedule the event 
    wp_schedule_event(current_time('timestamp'), $recurrence, 'my_func'); 
    } 
} 

我還試圖創建自定義的復發這樣

function isa_add_cron_recurrence_interval($schedules) { 

    $schedules['5sec'] = array(
     'interval' => 5, 
     'display' => __('Every 5 seconds', 'textdomain') 
); 
} 

add_filter('cron_schedules', 'isa_add_cron_recurrence_interval'); 

但預定功能只運行一次。 我錯過了什麼?

回答

0

這可能是一個老問題,但我有一個類似的問題:你的函數缺少return語句:

function isa_add_cron_recurrence_interval($schedules) { 

    $schedules['5sec'] = array(
     'interval' => 5, 
     'display' => __('Every 5 seconds', 'textdomain') 
); 
    return $schedules; 
}