WordPress发表文章“定时发布失败”代码版及插件版解决方法

最近因为需要大量整理教程想用一下定时发布功能,但是在测试过程中发现单独设置发布正常,如果批量更改时间就不行,提示定时发布失败,在网上查了一些资料,测试了一下,发现以下两种方法可以解决,供大家参考,文章来源第三方网站。

第一种方法:

将代码添加到当前主题 – 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 );

第二种方法:

推荐两款解决定时发布失败的插件:WP Missed Schedule Posts 和 MY Missed Schedule

 

WP Missed Schedule官方下载地址:http://wordpress.org/extend/plugins/wp-missed-schedule/

MY Missed Schedule官方下载地址:https://cn.wordpress.org/plugins/my-missed-schedule/advanced/

不管使用哪个办法,定时设置之后或者原来有大量定时发布失败的文章,需要在使用后等待五分钟左右,如果还是不行或者有更好的解决办法可以圈子留言交流。

© 版权声明
THE END
文章不错?点个赞呗
点赞0 分享
lyy