经常有用户说定时发布文章是提示失败,造成失败原因不太清楚,应该是主机慢有关吧,我自己从没遇到过,这里记录一下解决办法,供大家参考。
推荐两款解决定时发布失败的插件:WP Missed Schedule Posts和MY Missed Schedule
定时发布失败解决办法
WP Missed Schedule Posts
MY Missed Schedule
也可以用下面的代码,代码应该是提取自老版本的WP Missed Schedule Posts插件,将代码添加到当前主题 functions.php 中:
if (!function_exists( 'add_action' ) ) {
header( 'Status 403 Forbidden' );
header( 'HTTP/1.0 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
function wpms_log() {
echo"\n";
}
add_action( 'wp_head', 'wpms_log' );
add_action( 'wp_footer', 'wpms_log' );
define( 'WPMS_DELAY', 5 );
define( 'WPMS_OPTION', 'wp_missed_schedule' );
function wpms_replace() {
delete_option(WPMS_OPTION);
}
register_deactivation_hook(__FILE__,'wpms_replace');
function wpms_init() {
remove_action('publish_future_post','check_and_publish_future_post');
$last=get_option(WPMS_OPTION,false);
if (($last!==false)&&($last>(time()-(WPMS_DELAY*60))))return;
update_option(WPMS_OPTION,time());
global$wpdb;
$scheduledIDs=$wpdb->get_col("SELECT`ID`FROM`{$wpdb->posts}`"."WHERE("."((`post_date`>0)&&(`post_date`<=CURRENT_TIMESTAMP()))OR"."((`post_date_gmt`>0)&&(`post_date_gmt`<=UTC_TIMESTAMP()))".")AND`post_status`='future'LIMIT 0,5");
if (!count($scheduledIDs))return;
foreach($scheduledIDs as$scheduledID) {
if (!$scheduledID)continue;
wp_publish_post($scheduledID);
}
}
add_action( 'init', 'wpms_init', 0 );
代码添加后,定时发表文章还是会提示失败,但过二、三分钟后,会正常发布的。
至于哪个方法适合你,只能自己试了。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有