Tag: wordpress

Clean up WordPress post revisions

To delete the WordPress post revisions you only need one SQL statement. Execute this SQL query to remove all post revisions from your MySQL database:

DELETE a, b, c
FROM `wp_posts` a
LEFT JOIN `wp_term_relationships` b ON a.id = b.object_id
LEFT JOIN `wp_postmeta` c ON a.id = c.post_id
LEFT JOIN `wp_term_taxonomy` d
ON b.term_taxonomy_id = d.term_taxonomy_id
WHERE a.post_type = “revision”
AND d.taxonomy != “link_category”;
DELETE from `wp_posts` WHERE post_type=”revision”;

How to fix Schedule Missed error on WordPress posts

If you are experiencing then problem “scheduled missed” when scheduling a post in WordPress, I found the solution on http://blog.5ubliminal.com/.  Simply do the following:

  1. Copy the code shown below and save it as scheduled-mias.php.
  2. Upload the file to wp-content/plugins on your WordPress site
  3. From your dashboard, enable the plugin named Scheduled Mias

That’s all there is to it.


<?php

/*

Plugin Name: [Post] Scheduled MIA-s

Plugin URI: http://blog.5ubliminal.com/topics/wordpress/plugins/

Description: Bring the left-for-dead <code>Missed Schedule</code> (MIA) posts back to life.

Version: 5.U.B

Author: 5ubliminal

Author URI: http://blog.5ubliminal.com/

Support URI: http://blog.5ubliminal.com/support/

*/

// —————————————————————————– //

define(‘SCHEDULEDMIAS_DELAY’, 15); // Minutes .. change as you wish

define(‘SCHEDULEDMIAS_TRANSIENT’, ‘scheduled_mias’); // Minutes .. change as you wish

// —————————————————————————– //

class Schedules_MIAs{

public function Schedules_MIAs(){ $this->__construct(); }

public function __construct(){

add_action(‘init’, array($this, ‘onInit’), 1);

}

public function onInit(){

// I disable internal cron jobs for post publishing completely

// … Comment the line below to let WordPress try do its job before we kick in

remove_action(‘publish_future_post’, ‘check_and_publish_future_post’);

if(get_transient(SCHEDULEDMIAS_TRANSIENT)) return; // Make sure enough time elapsed since last run

set_transient(SCHEDULEDMIAS_TRANSIENT, 1, abs(intval(SCHEDULEDMIAS_DELAY)) * 60); // Reset delay

global $wpdb; // Global $wpdb object

// Find MIA post_IDs, try both LOCAL datetime and GMT datetime

$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'”

);

if(!count($scheduledIDs)) return; // None found … bail

foreach($scheduledIDs as $scheduledID){

if(!$scheduledID) continue; // Just in case

// Publish each post_ID the WordPress friendly way

wp_publish_post($scheduledID);

}

}

};

// —————————————————————————– //

$Schedules_MIAs = new Schedules_MIAs();

// —————————————————————————– //

?>