如何解决显示“错过日程”的预定帖子

时间:2011-03-31 作者:Martin-Al

我未来的帖子越来越“错过”。他们没有按时发布,上面写着“错过了时间表”。

我在某个地方读到,这可能是服务器问题,那么我如何修复它呢?

1 个回复
最合适的回答,由SO网友:Martin-Al 整理而成

在my theme的函数中添加了以下内容。php:

define(\'WPMS_DELAY\', 5);  // Run the below cron task every X minutes
define(\'WPMS_OPTION\', \'wp_missed_schedule\');

function wpms_replacements_deactivate() {
    delete_option(WPMS_OPTION);
}
register_deactivation_hook(__FILE__, \'wpms_replacements_deactivate\');

// Run the following code on every request
function wpms_init() {
    remove_action(\'publish_future_post\', \'check_and_publish_future_post\');
    $last = get_option(WPMS_OPTION, false);

    // Exit here if less than WPMS_DELAY minutes has passed since we last ran
    if (($last !== false) && ($last > (time() - (WPMS_DELAY * 60))))
        return;

    // Find all posts whose scheduled time has passed and publish them
    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, 10
    ");
    if (!count($scheduledIDs)) 
      return;
    foreach ($scheduledIDs as $scheduledID) {
        if (!$scheduledID) continue;
        wp_publish_post($scheduledID);
    }
}    
add_action(\'init\', \'wpms_init\', 0)

结束

相关推荐