我想使用默认函数在wordpress中运行cron作业。我想设定每15天运行一次的时间。我怎样才能为此设置?
function prefix_deactivation()
{
wp_clear_scheduled_hook('prefix_hourly_event_hook');
}
register_deactivation_hook(__FILE__, 'prefix_deactivation');
function prefix_activation()
{
wp_schedule_event(time(), 'everyminute', 'prefix_hourly_event_hook');
}
register_activation_hook(__FILE__, 'prefix_activation');
/* On activation, set a time, frequency and name of an action hook to be scheduled. */
function prefix_do_this_hourly()
{
// do something every hour
cronjob_options();
}
function cronjob_options()
{
/* your job */
}
add_action('prefix_hourly_event_hook', 'prefix_do_this_hourly');
答案 0 :(得分:1)
试试这段代码
add_filter( 'cron_schedules', 'cron_add' );
function cron_add( $schedules ) {
$schedules = array(
'everyminute' => array( 'interval' => 129600,
'display' => __( 'Every Minute' )
),
);
return $schedules;
}
答案 1 :(得分:1)
希望你能在wordpress中获得cron工作的完美答案
<?php
add_filter( 'cron_schedules', 'cron_add_everyday' );
function cron_add_everyday( $schedules ) {
// Adds once everyday to the existing schedules.
$schedules = array(
'everyday' => array( 'interval' => 86400*1,
//set cron time you want call 86400 for 1 day change 1 as per your days...
'display' => __( 'Every Day' )
),
);
return $schedules;
}
?>
答案 2 :(得分:1)
<?php
add_filter( 'cron_schedules', 'cron_add_day' );
function cron_add_day( $schedules ) {
$schedules = array(
'day' => array( 'interval' => 86400*1,
'display' => __( 'Every Day' )
),
);
return $schedules;
}
?>
答案 3 :(得分:0)
add_filter( 'cron_schedules', 'cron_add_everyminute' );
function cron_add_everyminute( $schedules ) {
$schedules = array(
'everyminute' => array( 'interval' => 60*60*24*15,
'display' => __( 'Every Minute' )
),
);
return $schedules;
}