3

My future posts are getting "missed". They are not getting published on the time they should, and it says "Missed Schedule".

I read somewhere that it could be a server issue, so how can I fix it?

3
  • Try the Missed Schedule plugin. Commented Mar 31, 2011 at 23:53
  • I found a plugin that was recently updated and used that. wordpress.org/extend/plugins/wp-missed-schedule Since there was only a small code, I didn't install the pluging, but used the code in my functions-file.
    – Martin-Al
    Commented Apr 2, 2011 at 19:45
  • this is a really old question, but if anyone is having the same error with a custom plugin/script that uses wp_insert_post, check post_date_gmt, in my case it was being set to GMT+3 local time, causing this issue
    – Cagri
    Commented Oct 18, 2022 at 21:10

1 Answer 1

0

Added the following to my theme's functions.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)
3
  • 2
    Could you explain what this actually does?
    – Vince P
    Commented Apr 10, 2013 at 10:03
  • This snippet was extracted to my old developmental version of plugin "WP Missed Schedule", the code that you have posted here is my code, and not public code, this code is obsolete, and break some Jetpack publicize functions. Without assign on this thread paternity of code and trademark at original authors, this is a violation of GPL. Is not my role to explain more. Please use only full "WP Missed Schedule" package available on GitHub github.com/sLaNGjI/wp-missed-schedule and not other obsolete coding.
    – sLa
    Commented Jun 19, 2017 at 17:37
  • @sLa If you believe this post is copyright infringement please contact StackExchange directly and they will investigate the claim further.
    – Howdy_McGee
    Commented Jun 19, 2017 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.