【发布时间】:2018-02-12 21:35:20
【问题描述】:
我想创建一个函数,该函数每 3 分钟运行一次。
我使用插件 wp-crontrol 来创建一个 cron 作业事件。
我在google和stackoverflow中搜索,function.php中的代码是
// Add a new interval of 180 seconds
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
function isa_add_every_three_minutes( $schedules ) {
$schedules['every_three_minutes'] = array(
'interval' => 180,
'display' => __( 'Every 3 Minutes', 'textdomain' )
);
return $schedules;
}
// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'isa_add_every_three_minutes' ) ) {
wp_schedule_event( time(), 'every_three_minutes', 'isa_add_every_three_minutes' );
}
// Hook into that action that'll fire every three minutes
add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' );
function every_three_minutes_event_func() {
// The code run update in every 3 minutes
$update= get_field('ls_home_number_candidates');
$updatePlusOne= $update++;
update_post_meta(56, 'ls_home_number_candidates', $updatePlusOne);
}
?>
然后在我的 WP-Cron 事件中出现名为 isa_add_every_three_minutes
的新事件但是事件没有运行。如果我按“立即运行”,则会出现类似“已成功执行 cron 事件 isa_add_every_three_minutes”的通知。
请帮忙。谢谢
【问题讨论】: