自己寫了一段每4小時要幫我執行匯入資訊的功能,但發現一直沒作用
// 添加一個定期事件來觸發匯入 RSS 的函數
function schedule_import_rss() {
if (!wp_next_scheduled('import_rss_event')) {
// 使用 wp_schedule_event 設定每4小時執行一次
wp_schedule_event(time(), 'fourhourly', 'import_rss_event');
}
}
add_action('init', 'schedule_import_rss');
此時就要搬出專門管理cron的外掛 Advanced Cron Manager
安裝後可工具中找到管理頁面,進入後搜尋 "import_rss_event",果然沒找到
接著我們要自己手動新增,點撃左上角的新增事件
勾點填入 import_rss_event
時間就選一個要執行的時間,可依照目前+你想要執行的時段去填
排程就依照上面,看你要1天1次或1天兩次,引數不用填
弄完後回存,搜尋 import_rss_event 就能找到
然後可以手動執行看看會不會work