文章目录
对于网站运营而言,定时更新有质量的文章是每天必做的事情。然而,有时候使用WordPress建站的朋友会发现:定时发布失败。鉴于这种情况的话,如何处理呢?下面,浪子虎就对基于WordPress站点的定时发布失败这一问题作一个探讨。
推荐看下这篇文章
下面,是浪子虎推荐的几个解决方案。
修改源码
这是第一种方法。找到网站根目录wp-includes文件夹里的cron.php文件,打开,大约在291行,找到如下代码:
1 2 3 4 5 6 7 8 9 10 |
$cron_request = apply_filters( 'cron_request', array( 'url' => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ), 'key' => $doing_wp_cron, 'args' => array( 'timeout' => 0.01, 'blocking' => false, /** This filter is documented in wp-includes/class-http.php */ 'sslverify' => apply_filters( 'https_local_ssl_verify', false ) ) ) ); |
将其中的0.01修改为大一点的数字,比如:1.00,5.00等等,只要比0.01大就行。那么,这是为什么呢?因为0.01代表的是wordpress发布文章的时长,修改为其他的数字实质上就是为了延长WordPress发布文章的时长。修改完成之后,保存覆盖即可。
修改数据库
具体方法位:到mysql的结构里找到wp_posts表里的post_status字段,将 inherit 修改为publish。
当然了,这种方法需要对数据库比较熟悉。如果是新手的话,笔者不推荐这样做。
使用插件
WordPress的好处就是插件很多。关于这一问题,也可以用插件的形式来解决。只需要下载或后台安装 WP Missed Schedule 即可。
当然了,如果不想安装插件的朋友,也可以将插件的代码复制到 functions.php 中即可,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?php if(!function_exists('add_action')){ header('Status 403 Forbidden');header('HTTP/1.0 403 Forbidden');header('HTTP/1.1 403 Forbidden');exit();} ?> <?php function wpms_log(){ echo"\n<!--Plugin WP Missed Schedule 2011.0920.2011 Active-->"; } add_action('wp_head','wpms_log'); add_action('wp_footer','wpms_log') ?> <?php 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) ?> |
至此,WordPress后台定时发布功能失败的问题就已经解决了。笔者比较推荐的解决方案是第一种,之后是第三种,不推荐第二种。当然了,如果其中的某种方法你试了之后还不能解决的话,可以试试其他的方法。
