【发布时间】:2016-03-18 18:20:50
【问题描述】:
我想使用 WordPress 调度在一段时间后回显一个字符串。下面是我在functions.php中的代码。通过 echo 语句没有打印任何内容,也没有错误。请指导我做错了什么。
function add_new_intervals($schedules) {
// add weekly and monthly intervals
$schedules['now'] = array(
'interval' => 1,
'display' => __('Once Weekly')
);
return $schedules;
}
add_filter( 'cron_schedules', 'add_new_intervals');
function my_activation() {
if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
wp_schedule_event( current_time( 'timestamp' ),'now', 'my_hourly_event');
}
}
add_action('wp', 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
function do_this_hourly() {
echo "This is the Text";
}
【问题讨论】:
-
有礼貌地首先在一个网站上询问(然后看看你得到什么回应),而不是交叉发布到多个网站。 wordpress.stackexchange.com/questions/221104/…(或者下一次,在从一个 SE 站点复制粘贴到另一个站点时,要足够聪明地忽略“0 反对票喜爱”部分。)
标签: php wordpress cron task scheduling