自定义$recurrance参数wp_schedule_event


wp_schedule_event for custom $recurrance parameter

我在wp_schedule_event中有一个关于其第二个参数的问题,该参数声明了触发钩子函数的时间。 根据 https://codex.wordpress.org/Function_Reference/wp_schedule_event,它有三个有效值:'hourly''twicedaily ' 和 'daily'

如果我希望它每 48 小时运行一次怎么办?可能吗?

您可以创建自定义计划间隔。

例如;将其添加到您的函数.php或其他相关位置:

add_filter( 'cron_schedules', 'gadss_add_twodays_cron_schedule' );
function gadss_add_twodays_cron_schedule( $schedules ) {
    $schedules['twodays'] = array(
        'interval' => 172800, // 2 days in seconds
        'display'  => __( 'Once every two days' ),
    );
    return $schedules; 
}