Archive for the ‘PHP’ Category

Deleting WordPress Post Revisions

Saturday, February 25th, 2012

To all WordPress bloggers: As a blogger who has used WordPress blogging software for his blogs for several years, I often find that the number of saved post revisions grows quite large in a short time, especially since I’m constantly updating my collection of blog posts.  Deleting WordPress post revisions   occasionally, becomes necessary to preserve efficient WordPress database operation.  While I wish to retain the post revisions for a week or two, those older ones I can certainly do without.  Indeed, one sure way to better   optimize the WordPress database   is to keep only the posts, comments, and other data that you actually need, in order to keep your blog quickly responding to page requests and to shorten the time required for a WordPress database backup to complete.

So, each time I back up my blog databases, I first delete the WordPress post revisions I no longer want.  Remember that each time you save a post during editing, a new post revision record is created in the WordPress database.  Therefore, if you make many revisions to a document, you’ll create many copies of it saved in the database.  If the document is a large one, the amount of storage required for it and its revisions quickly becomes significant.  So be sure to periodically delete those WordPress post revisions regularly to help keep your blog running at top speed.

To delete WordPress post revisions, use the following procedure:

  1. Log into yout MySQL account that hosts your WordPress blog’s database you’re working with.
  2. Then, execute the following SQL statement in the quotes: “DELETE FROM wp_posts WHERE post_type = “revision”;”  Note that this particular SQL statement removes all post revisions.  However, you could add timestamp constraints, to, for example, delete only those post revisions that are more than two weeks old.
  3. You should then see a response from MySQL, telling you how many records were actually deleted from the wp_posts table.
  4. If you have no further tasks, log out of your MySQL account.

I’ve successfully executed the above procedure for WordPress 2 and WordPress 3 blogs.  So I expect that you will experience no problems with it on your WordPress blogs.  Indeed, it would be possible to automate this command into a PHP script that you could run with task scheduling software (like UNIX Cron).  Good luck.

Tom Hesley

Related Posts

Disabling Post Revisions: WordPress 3.0.4

Saturday, January 15th, 2011

I discovered that WordPress was again saving every revision of every post after I upgraded the   Tom’s Views   blog to WordPress 3.0.4, though I had disabled this feature during the last WordPress upgrade.  Click   here   for more details.  But apparently, in this latest version, the automatic retention of these revisions became enabled once more. So I turned off this feature by commenting out line 4404 in the wp-includes/post.php file as follows:

Line 4404 was:

if ( ! WP_POST_REVISIONS )

but now, it’s:

// if ( ! WP_POST_REVISIONS )

Then I deleted all the revisions that had been saved to this point since applying the WordPress upgrade from each blog database, by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = “revision”;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have now been verified to work with WordPress 3.0.2.

That’s all.

Tom Hesley

Related Posts

Disabling Post Revisions: WordPress 3.0.3

Saturday, December 11th, 2010

I discovered that WordPress was again saving every revision of every post after I upgraded the   Tom’s Views   blog to WordPress 3.0.3, though I had disabled this feature during the last WordPress upgrade.  Click   here   for more details.  But apparently, in this latest version, the automatic retention of these revisions became enabled once more. So I turned off this feature by commenting out line 4404 in the wp-includes/post.php file as follows:

Line 4404 was:

if ( ! WP_POST_REVISIONS )

but now, it’s:

// if ( ! WP_POST_REVISIONS )

Then I deleted all the revisions that had been saved to this point since applying the WordPress upgrade from each blog database, by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = “revision”;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have now been verified to work with WordPress 3.0.2.

That’s all.

Tom Hesley

Related Posts

Disabling Post Revisions: WordPress 3.0.2

Saturday, December 4th, 2010

I discovered that WordPress was again saving every revision of every post after I upgraded the   Tom’s Views   blog to WordPress 3.0.2, though I had disabled this feature during the last WordPress upgrade.  Click   here   for more details.  But apparently, in this latest version, the automatic retention of these revisions became enabled once more. So I turned off this feature by commenting out line 4404 in the wp-includes/post.php file as follows:

Line 4404 was:

if ( ! WP_POST_REVISIONS )

but now, it’s:

// if ( ! WP_POST_REVISIONS )

Then I deleted all the revisions that had been saved to this point from each blog database by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = “revision”;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have now been verified to work with WordPress 3.0.2.

That’s all.

Tom Hesley

Related Posts

Disabling Post Revisions: WordPress 3.0.1

Sunday, October 31st, 2010

I discovered that WordPress was again saving every revision of every post after I upgraded the   Tom’s Views   blog to WordPress 3.0.1, though I had disabled this feature during the last WordPress upgrade.  Click   here   for more details.  But apparently, in this latest version, the automatic retention of these revisions became enabled once more. So I turned off this feature by commenting out line 4404 in the wp-includes/post.php file as follows:

Line 4404 was:

if ( ! WP_POST_REVISIONS )

but now, it’s:

// if ( ! WP_POST_REVISIONS )

Then I deleted all the revisions that had been saved to this point from each blog database by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = ‘revision’;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have now been verified to work with WordPress 3.0.1.

That’s all.

Tom Hesley

Related Posts

Disabling Post Revisions: WordPress 3.0

Saturday, June 26th, 2010

I discovered that WordPress was again saving every revision of every post after I upgraded the   Tom’s Views   blog to WordPress 3.0, though I had disabled this feature back in March.  Click   here   for more details.  But apparently, in this latest version, the automatic retention of these revisions became enabled once more. So I turned off this feature by commenting out line 4398 in the wp-includes/post.php file as follows:

Line 4398 was:

if ( ! WP_POST_REVISIONS )

but now, it’s:

// if ( ! WP_POST_REVISIONS )

Then I deleted all the revisions that had been saved to this point from each blog database by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = ‘revision’;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have now been verified to work with WordPress 3.0.

That’s all.

Tom Hesley

Related Posts

Disabling Post Revisions: WordPress 2.9.2

Monday, May 10th, 2010

I discovered that WordPress was again saving every revision of every post, though I had disabled this feature back in March.  Click   here   for more details.  But apparently, in the upgrade to 2.9.2, the automatic retention of these revisions became enabled once more. So I turned off this feature by adding the following lines of code to the wp-config.php file at lines 27 and 28 for each of my blogs:

// Disable post revisions.
define(’WP_POST_REVISIONS’, false);

I also changed line 618 in the wp-settings.php file from

$default_constants = array( ‘WP_POST_REVISIONS’ => true );

to

$default_constants = array( ‘WP_POST_REVISIONS’ => false );

Also note that the line number has not changed from what it was in WordPress 2.9.1.

Then I deleted all the revisions that had been saved to this point from each blog database by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = “revision”;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have been verified to work with WordPress 2.9.2.

That’s all.

Tom

Related Posts

Today’s Business: 2010-02-25

Thursday, February 25th, 2010

Today’s Activities

  • Shower.  DONE.
  • Schedule appointment for Mom with the retina specialists in Johnstown for sometime in April, 2010.

Log

07:50 AM: I’m up. My weight is unchanged from yesterday.  It’s still  177.0 Lbs.

09:00 AM: I applied a software change to all my blogs that shortens all title tags for single posts; it eliminates the string:  Blog Archive  as well as one separator character from the titles.  This should fix the issues raised by my hosting provider about some of my title tags containing too many characters.  Presumably now, search engines will index more of my posts.  I’m not sure that this is actually true.  But the IT folks at my hosting company know lots more about this stuff than I do.  So I’ll take their word for it and bring the blogs into compliance.  Next thing to do, they suggest, is to remove all duplicate titles.  I did this for   Tom’s Diary  so far.  I’ll get to work on   Tom’s Love Quest   now.

11:20 AM: Spent the past couple hours categorizing posts on the   Tom’s Love Quest   blog.  I added categories for AffirmationsAloneness,  Cheating,   and   Loneliness   among others.

01:30 PM: Watched today’s episode of   The Young and the Restless   with   [Emmy].

02:50 PM: We dined at our favorite Indian restaurant: Tamarind Flavor of India, on Craig Street in Oakland.  Yum.

03:00 PM: Categorized more posts on the   Tom’s Love Quest   blog.  Now, there are just 18 left to do.   Details   here.

04:00 PM: Watched today’s episode of   Dr. Phil.

06:00 PM: Made numerous revisions to the   Tom’s Love Quest   blog.

07:30 PM: Watched tonight’s episodes of    NBC’s Nightly News    and   The CBS Evening News   TV news shows.

12:25 AM: Read four more chapters of the book:  The Drunkard’s Walk: How Randomness Rules Our Lives   by Leonard Mlodinow.

12:30 AM: Bed time.  See you tomorrow.

Tom Hesley

Related Posts

Disabling Post Revisions: 2010-02-17

Wednesday, February 17th, 2010

Disabling (or turning off) the retention of post revisions in WordPress 2.9.2 involves the same procedure as it did in WordPress 2.9.1.  Click   here   to view that procedure.

Click   here   for details of the WordPress 2.9.2 upgrade, that prompted this adjustment.

Tom

Related Posts

Disabling Post Revisions: WordPress 2.9.1

Thursday, January 21st, 2010

I discovered that WordPress was again saving every revision of every post, though I had disabled this feature back in March.  Click   here   for more details.  But apparently, in the upgrade to 2.9.1, the automatic retention of these revisions became enabled once more. So I turned off this feature by adding the following lines of code to the wp-config.php file for each of my blogs:

// Disable post revisions.
define(’WP_POST_REVISIONS’, false);

 I also changed line 618 in the wp-settings.php file from

$default_constants = array( ‘WP_POST_REVISIONS’ => true );

to

$default_constants = array( ‘WP_POST_REVISIONS’ => false );

Also note that the line number has changed from 576 in 2.8.5 to 618 in 2.9.1.

Then I deleted all the revisions that had been saved to this point from each blog database by executing the following SQL statement:

DELETE FROM wp_posts WHERE post_type = ‘revision’;

I then logged out and back into each site’s admin id and verified that the revisions saved thus far no longer appear on the Edit Post screen. The deletion apparently worked.   These instructions have been verified to work with WordPress 2.9.1.

That’s all.

Tom

Related Posts