dqkyz02602 2014-12-08 04:48
浏览 42

每x个小时的Wordpress cron时间表

I have the following code to execute cron job in every 3 hours to display time in the head.But it didn't work.

register_activation_hook( __FILE__, 'wpce_prefix_activation' );
function wpce_prefix_activation() {
    wp_schedule_event( current_time ( 'timestamp' ), 10800, 'prefix_three_hourly_event_hook' );
}

add_action( 'prefix_three_hourly_event_hook', 'wpce_prefix_do_this_three_hourly' );
function wpce_prefix_do_this_three_hourly() {
    // do something every hour
    add_action('wp_head', 'add_link_in_head');

} // end function

function add_link_in_head(){
  echo time();

}//end of function

register_deactivation_hook( __FILE__, 'wpce_prefix_deactivation' );
function wpce_prefix_deactivation() {
    wp_clear_scheduled_hook( 'prefix_three_hourly_event_hook' );
}



    add_filter( 'cron_schedules', 'filter_cron_schedules' );
// add custom time to cron


 function filter_cron_schedules( $schedules ) {
        $schedules['fively'] = array(
            'interval' => 300,
            'display' => __('Once in Five minutes')
        ); 



$schedules['in_per_minute'] = array(
    'interval' => 60,
    'display' => __('In every minute')
);  

$schedules['in_per_ten_minute'] = array(
    'interval' => 600,
    'display' => __('Once in Ten minutes')
); 

$schedules['1_hours'] = array(
    'interval' => 3600,
    'display' => __('Hour')
);


$schedules['three_hourly'] = array(
    'interval' => 10800,
    'display' => __('Once in three hours')
);  
return $schedules;
}

I want to run the cron job in wordpress every 3 hours,5 hours,6 and 7 hours.

If anyone can help it would really appreciate. Thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP