How to delete old post revisions in WordPress. WordPress editions, revisions and autosave. How to delete all revisions and editions

Good afternoon everyone. Today I wrote for you a purely technical article that allows you to optimize your WordPress blog database by cleaning revisions (automatically saved copies of articles). We will take a detailed look at and analyze the purpose of revisions, their essence, and I will also show you how to delete and disable or limit the appearance of revisions in WordPress. The material published below will be accompanied by detailed pictures with comments.

As you can see, there are quite a lot of questions to study. True, for many owners of Internet resources it will not be new, but the “smartest” do not read my blog, it is read by those who want to learn. To create a popular, reliable and stable website, beginners need to understand all the technical intricacies and have a practical understanding of revisions and much more. Will learn.

What are revisions in WordPress

Perhaps you have noticed that while writing or editing a post, the system automatically makes a copy of it - a backup save. At this time, the “Publish” and “Save” buttons located in the window on the right become inactive. This action is called revision.

Revisions in WordPress are an automatic backup of the contents of a post or page to prevent data loss. From them you can restore earlier copies of documents.

Many people have probably guessed that WordPress revisions are used to avoid data loss. They are configured automatically and make a backup copy after a certain period of time (every 60 seconds). They are added to a database (MySql - phpMyAdmin). You can view the list of revisions in WordPress just below the post edit window (in edit mode). If you scroll the page, you can see them just below in the “Editors” window. They look like this:

You probably already have the question “Why delete or disable revisions?” if they play such a useful role. The whole problem is that copies of records, articles or posts greatly load the database into which they are entered. This leads not only to the future problem of editing and making changes, but also to slow loading of site pages. I advise you to read the post "". Search engines began to pay special attention to this parameter. Also, by the way, the behavioral factor directly depends on this, the indicator of which is formed from an assessment of user behavior.

Naturally, we need to get rid of revisions, no matter how useful they may be. This will not only reduce the size and volume of the database, but also load the site much faster.

How to Delete Revisions in WordPress

There are different ways to delete revisions, I will show two. One is aimed at dummies, such as I was recently, and the second at people who are more prepared (who are not afraid of servers and databases).

Method number 1. Better Delete Revision plugin

We will use a specially created plugin for deleting revisions - Better Delete Revision. Download it via Admika and install it. After activation, an item with a name similar to the name of the plugin will appear in the settings section - these are settings.

You can immediately optimize the database or go to the “Check revision records” tab and from there clean your blog from unnecessary copies of documents.

Method No. 2.Deleting directly from the database

This one is a little more difficult to implement. I don't want to scare you, but if you are afraid of doing something wrong, then it is better to skip it. In this method, we will delete copies of articles directly through the database itself. Just before going there, I advise you to make a copy of it. If you don't know how to do this, then read the post.

After selecting the desired database, find the “SQL” tab, open it so that an empty field appears in front of you.

You need to copy the code below into it and click on the “OK” button. With this action you will make an SQL request to delete revisions from the database.

DELETE FROM wp_posts WHERE post_type = "revision";

It should look like the picture:

If your actions are successful, you will see a message like the following in response. If you have not previously deleted or disabled revisions, then the number of lines will be different from zero.

How to Disable WordPress Revisions

In order not to waste time on cleaning each time, the creation of backup copies of articles can be disabled. Then your “Editors” window will simply disappear and permanent saving will stop happening. Please think very carefully before doing this, as you will no longer be able to open or return to the previous version of the entry.

To disable revisions, you need to go to your hosting and edit the wp-config.php file, which is located in the root folder. Paste the code with the parameter into it:

Define("WP_POST_REVISIONS", 3);

The number sets the number of document versions that will be stored in the database. Limit it to the number you need, for example one would mean you have one published and one backed up (last edited).

After finishing making changes, click on the “Save” button. Now your database will not swell like yeast dough every time you edit articles.

This is where I end this post. I hope this information was useful to you. If you have any questions, please leave them in the comments.

Want to get rid of unnecessary clutter in your WordPress database? Disable post revisions! If interested, read on.

What are revisions?

When you create a new post or page on the site, then save it, and then edit it several times, the “engine” automatically saves all its versions in its database. They are called revisions.

Why disable revisions in WordPress?

If your site has no more than one dozen entries, then there is nothing to worry about. But if there are more than one hundred of them, it’s worth thinking about. After all, one article can be corrected several dozen times until it is published. This means that several dozen copies of it will be stored in the database. In principle, on the one hand, this is convenient, since it allows you to view all changes, return some of them, etc. But after the publication is posted on the site, no one needs its duplicates.

How to disable revisions in WordPress?

If you are the happy owner of a multifunctional premium plugin, then you will not have to look for any other solutions. One of its functions is to completely disable the creation of revisions. To do this you need to go to the admin section Clearfy Pro and on the tab Additionally activate setting Disable revisions completely.

other methods

Revision Control plugin

Revision Control is a separate plugin for managing revisions on a WordPress website. Its main feature is the ability to specify for which types of posts (Pages or Posts) the creation of copies should be prohibited.

So, after installing and activating it, you should go to the admin panel Settings -> Revisions.

You can disable the creation of revisions for the desired post type. The corresponding fields are used for this: Posts and Pages. To save all changes, click the Save Changes button.

Disable Post Revision plugin

Disable Post Revision is a separate plugin that performs only one function - completely disabling the creation of copies of content. To do this, you just need to install and activate it. The main advantage of the plugin is the absence of any settings pages. It starts doing its job immediately after activation.

Hello everyone, my dear readers of the site. Not long ago we looked at a WordPress theme. But just the other day I had to add one more method to this article. Extremely effective when you have been blogging for a long time, provided that you did not know this trick.

These so-called revisions or, in other words, editions have existed since older versions of cms Wordpress.

Why are post revisions needed?

Revisions of posts and pages are needed only in theory. The point is that they save a backup copy of your article in a database. Moreover, saving occurs every time you change.

It turns out that in the process of writing an article, when you click the “Save” button, a copy of your article is created with your changes. And at any time you can look at the list of these copies and select the most suitable one and restore it.

In all my practice, I have only had to restore a copy from such reserves once. But nonetheless.

On the face of it, the feature seems quite useful. However, you must understand that each such save is an extra load on the database, because all copies are stored there.

Here's an example from life. On average, I had 4-5 revisions of each article on my blog. Imagine when you have hundreds of articles written, and perhaps thousands of articles - by removing revisions (editions) of posts - you will thereby speed up your blog by 5 times.

What if you don’t have 5 revisions, but 10 for each post? By the way, how much do you have, if it’s not a secret? Please write about this in the comments.

By the way, the most interesting thing is that when you don’t even click on the “Save” button, post revisions are created automatically. This is called autosave.

How can I limit the number of post edits?

We already know that all revisions are stored in a database. To change their number, we need a standard “filter”, which is called wp_revisions_to_keep, or using the WP_POST_REVISIONS directive in the wp-config.php file.

By the way, for some reason the directive in the wp-config file did not work for me. Write, for whom does it work in new versions of WordPress?

So, let's say we want to leave the ability to save revisions, but leave, say, only 3 pieces. To do this we need to write the following:

Function my_revisions_to_keep($revisions) ( return 3; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Using wp_revisions_to_keep you can also limit the number of copies in different post types. More precisely, in one type there is one number of revisions, in another - another.

Well, for example, let’s say you need 5 revisions for pages and 3 revisions for articles (posts) and other types of posts.

Function my_revisions_to_keep($revisions, $post) ( if ("page" == $post->post_type) return 5; else return 3; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep", 5, 2);

You can also try using WP_POST_REVISIONS in the wp-config.php file, but this method does not allow you to separate post types.

define("WP_POST_REVISIONS", 3);

How to disable and/or delete revisions in wordpress

In the same way, you can refuse revisions altogether. You just need to put the number 0 in the restrictions.

Function my_revisions_to_keep($revisions) ( return 0; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Or using the wp-config.php file:

Define("WP_POST_REVISIONS", 0);

The most important. Disabling revisions will not affect their existence (already existing ones) in any way. those. if you had 3-5 revisions for each article and you disabled revisions, old copies of posts will still remain. They need to be deleted manually through the database.

How to delete all revisions and editions

So, we disabled the editors. WE already know that simply disabling editors is not enough. You need to uproot them and delete them manually via MySQL.

Let's get started, I guess. But before you delete anything, make a backup. It's better to make a backup of the entire site.

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

We do something similar for taxonomies

DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

And of course, we delete the revisions themselves.

DELETE FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%";

This MySQL query will delete all revisions in your database. Except for autosaves.

Autosave is also considered a revision, but they are not deleted or disabled!! Therefore, to keep them as small as possible, write the texts in advance in Word, and then simply paste them into the admin area!

A little reminder on how to work with MySQL

In case you forgot.

I work with adminvps hosting, I even told you why in this article. So, I will show everything on it.

Login to phpMyAdmin in your hosting control panel.

Enter your login and password.

We selected the database we needed and clicked the SQL button, which is located at the top.

And we see a large field for writing SQL queries. For the entire Database.

There we enter all requests in order.

Don't worry if you see zero values, it means you simply didn't use left post types or taxonomies.

And this is what I got using the last request.

Look how my blog became faster after this. It's just a fairy tale!

I'm sure you have the same thing! Check it out and write me back about it later.

Plugin for working with post editors

I can also recommend the Revision Control plugin, it allows you to do the same thing as I described, only in a more comfortable mode for you. Right in the admin panel.

If you still have questions, ask, I will be happy to help you. That's all for now. Thank you for your attention.

When you create, edit, and save articles and their drafts in WordPress, by default, post backups are automatically created, commonly referred to as Revisions or Editions(revisions).
Saving revisions is of course useful, since, for example, if there are errors in the formatting of the material, or failures of your computer or server, you are given the opportunity to restore any of the previous versions of your recording. But the functionality of saving revisions also has a negative side.

After all, all backup copies (revisions, editions) are stored in your blog’s database, in a table wp_posts. And if you have created a lot of records, and at the same time they were often edited, then the size of the database will be too large. In addition, the execution of queries to the database will slow down.

You can see the list of available revisions at the bottom of the post editing page:

Revisions, edits of WordPress posts

Disable, restrict, delete WordPress revisions It turns out it's not difficult at all.
Let's look at everything in order using WordPress 3.3.1 as an example.

But just remember to back up your database before making modifications!

Disabling revisions in WordPress

In order to disable the creation of revisions (editions), you need to add one line to the file wp-config.php

Define("WP_POST_REVISIONS", 0);

Define("WP_POST_REVISIONS", false);

There is another option for disabling revisions - change one of the values ​​from “true” to “0” or “false” in the function wp_functionality_constants(), which is in the file /wp-includes/default-constants.php

Function wp_functionality_constants() ( ... if (!defined("WP_POST_REVISIONS")) define("WP_POST_REVISIONS", false); ...

Limit the number of revisions in WordPress

In order to limit the number of revisions (editions), you need to add one line to the file wp-config.php, as it was when disabling revisions, but instead of the value “0” or “false” specify an integer:

Define("WP_POST_REVISIONS", 3);

In this case, a maximum of 3 revisions will be created per article, plus one “AutoSave” copy.

Note for memory:
Making the above changes will not immediately reduce the number of revisions that already exist in the database. But the changes will take effect when updating existing records, and separately. They will also be taken into account when creating new entries. It is also worth considering that in the editing mode, in addition to revisions in the database, one single copy of the record will be recorded every 60 seconds as “Auto-save”.

Remove all WordPress revisions from database

If your blog has existed for a long time and has a lot of posts, then it won’t hurt to optimize its database by deleting previously created revisions (editions), and thereby reduce the size of the table wp_posts.

Attention! Don't forget to back up your database before deleting all revisions! Otherwise, it will no longer be possible to restore deleted revisions.

So, we need to perform several actions:

1. Log in to your database control panel, for example phpMyAdmin;
2. Select the name of the database that is used by your blog;
3. Click on the button (or tab) labeled “SQL” (usually it is located at the top of the page);
4. In the SQL queries field, enter this query:

DELETE FROM wp_posts WHERE post_type = "revision";

5. Click the “Ok” button to complete the request;

That's all. Now the database of your blog, or more specifically the table wp_posts, has greatly decreased in size.

Finally, I would like to say that the above example of deleting revisions(editions) is the simplest and most inflexible. You may want to delete not all revisions, but selectively, for example, leaving the last three revisions in each entry. In this case, you will either have to run a more advanced query in the database, or use a special plugin. Fortunately, there are plenty of plugins for managing revisions and databases.

Hello dear readers. Today I'd like to talk about revisions in WordPress, how you can limit the number of times they are saved in the database per post or page, and how to disable and delete them completely.

What are editions and why are they needed?

Editorials (revisions) in WordPress- These are backup copies that are saved in the database every time a post or page is updated. On the one hand, this is convenient, since you can always restore a backup copy of an article at any time, because WordPress saves absolutely all backup copies. But let's imagine that you have a highly loaded project with high daily traffic and a huge amount of content. What then? Then the database may experience enormous loads. What can we do? If you still need revisions of posts and pages, you can limit the number of times they are saved, or you can completely disable and delete them, thereby reducing the load.

Limiting the number of revisions saved

The number of revisions in WordPress can be limited in two ways:

  1. Using the constant WP_POST_REVISIONS;
  2. Using the wp_revisions_to_keep hook (this hook also allows you to select the type of posts for which the restriction is set, be it standard or custom post types).

In order to limit the number of saving revisions using the WP_POST_REVISIONS constant, you need to add the following code to the wp-config.php configuration file (it is located in the root of the site):

Define("WP_POST_REVISIONS" , 1);

Now, for each post and page, one revision will be stored in the database.

As I wrote above, the wp_revisions_to_keep hook gives more options. Below is an example of code to limit the number of saved revisions with comments, which you need to add to your theme's functions.php file:

/** * Limiting the number of saving revisions using the wp_revisions_to_keep hook * @param integer $count - number of revisions * @param object $post - post object */ function limit_save_revisions_db($count, $post) ( if ($post->post_type = = "page") (//for standard WordPress pages, save 1 revision return 1; ) elseif ($post->post_type == "post") (//for standard WordPress posts, save 3 revisions return 3; ) elseif ($post ->post_type == "reviews") (//for the custom post type "Reviews" we do not save revisions return 0; ) else (//for all others we save 3 revisions return 3; ) ) add_action("wp_revisions_to_keep", "limit_save_revisions_db" , 10, 2);

Complete disabling and deleting revisions

If you decide to disable revisions on your site altogether, you can also use the wp_revisions_to_keep hook by adding the following code to your theme’s functions.php file:

/* * Total revision deactivations * @param integer $count - number of revisions */ function deactivate_revisions($count) ( return 0; ) add_filter("wp_revisions_to_keep", "deactivate_revisions");

In addition, after completely disabling editions, it is advisable to delete them from the database. After all, before the shutdown, they were still preserved and will now lie there as unnecessary “dead” weight. To do this, you need to go to PHPMyAdmin, find the desired database and open the wp_posts table in it. Next, click on the SQL tab and execute the following query:

DELETE FROM `wp_posts` WHERE post_type = "revision";

Now you need to delete all metadata (wp_postmeta table) and taxonomies (wp_term_relationships table) of the editions. To do this, we run 2 more queries:

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%"); DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

Of course, it's best to back up your database before running these queries.

That's all. I hope the article was useful to you. Good luck to all!!!