Publish Posts That Missed Their Schedule
Checks every few minutes for scheduled posts stuck with a "Missed schedule" label and publishes them, a common problem on low-traffic sites.
Opens WPIDE on
Code
// How often to check, in seconds.
$wpide_missed_check_every = 5 * MINUTE_IN_SECONDS;
add_action( 'init', function () use ( $wpide_missed_check_every ) {
if ( get_transient( 'wpide_missed_schedule_lock' ) ) {
return;
}
set_transient( 'wpide_missed_schedule_lock', 1, $wpide_missed_check_every );
$missed = get_posts( array(
'post_type' => 'any',
'post_status' => 'future',
'date_query' => array( array( 'column' => 'post_date_gmt', 'before' => gmdate( 'Y-m-d H:i:s' ) ) ),
'numberposts' => 10,
'fields' => 'ids',
'suppress_filters' => true,
) );
foreach ( $missed as $post_id ) {
wp_publish_post( $post_id );
}
}, 30 );
Notes
A real server cron hitting wp-cron.php is the long-term fix; this is a safety net.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.