WordPress 使用“Bulk edit publish date”定时发布失败解决方案。
- 网建应用
- 2025-03-15
- 20热度
- 0评论
想尝试一下WP的定时发布功能,发现在手动发布的时候一切正常能正常的发布。但是在用“Bulk edit publish date”插件的时候就一直提示“定时发布失败”
经过各种尝试,得出以下两种解决方案。
插件解决方案
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 );
代码添加后,定时发表文章还是会提示失败,但过二、三分钟后,会正常发布的。
以上两种方案至于哪个更适合你,只能自己试了。我是用代码的方案测试没问题。。