• Functionality of the history of changes (revisions) in WordPress: how to work with it. Delete old editions and free up space in the Wordpress database Wordpress editions

    By default, WordPress saves all revisions of posts and articles during intermediate saves during the editing process. Along with revisions, other information can be saved in the database: their metadata and taxonomy. It is unlikely that they can have any negative impact on a small site, but over time the database will grow, and the revisions in it will occupy a much larger volume than the published pages and posts.

    Before disabling revisions and deleting old editions, be sure to back up your site files and database.

    Disabling or limiting revisions

    Saving post and page revisions in the WordPress site database can be disabled or limited in number. To do this you need to open the file wp-config.php and, to disable saving revisions completely, add the line:

    Define("WP_POST_REVISIONS", false);

    In order to limit the number of saved revisions, replace the word in the added line false by a number corresponding to the desired number of saved revisions. For example, to save 3 revisions, the added line will look like this:

    Define("WP_POST_REVISIONS", 3);

    Number 0 in this expression will match the keyword false.

    Please note that the added line must be placed in the wp-config.php file after the line:

    Define("WP_DEBUG", false);

    and before the line:

    I added this:

    Define("WP_DEBUG", false); /* Cancel or limit the number of revisions */ define("WP_POST_REVISIONS", false); /* That's all, no further editing. Good luck! */

    Removing all old revisions

    If you did not immediately disable saving revisions, then there might already be quite a lot of them and, if desired, old revisions can be deleted. To do this, you need to log into the phpMyAdmin application, select a database and go to the SQL tab:

    Before deleting all revisions from your WordPress site's database, you must first remove their metadata and taxonomy, if any. Copy and paste the following three commands into the input field one by one and click the “Forward” button. If you specified a prefix other than “wp_” for your database tables when installing WordPress, replace “wp_” in the commands below with your prefix.

    Removing Meta Data

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

    and press the “Forward” button.

    Removing a taxonomy

    copy and paste the following line into the SQL query input field:

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

    and press the “Forward” button.

    Delete all revisions

    copy and paste the following line into the SQL query input field:

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

    and press the “Forward” button.

    After executing each command, you will see in the information window how many rows were deleted from the database.

    After creating another website on WordPress, I remembered about revisions when I was almost finished working on the first post. When deleting, the following results were obtained:

    • meta data - 0 rows removed;
    • taxonomy - 0 rows removed;
    • revision - 33 lines were deleted.

    Editing one post, which was not yet completed, created 33 revisions that I didn't need. No metadata or taxonomy associated with revisions was created.

    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 still.

    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? Write about it in the comments please.

    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");

    With 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 by 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 is 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.

    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 everyone!!!

    Saving changes to posts can be very useful when working in WordPress. If something goes wrong and you lose information from a post, you can always access a previous saved version of your post by simply clicking on the link in the menu Editorial under the editor window.

    Many, many revisions

    If you've been working with WordPress for a while, then you've undoubtedly used this feature once or twice. But you've probably noticed that these changes tend to accumulate.

    If you write a post in the editor, then WordPress saves revisions automatically when you save the post. As a result, it is not uncommon to have more than 20 edits to a post. Multiply this by the number of posts on your site, and you get megabytes of additional posts stored in the database.

    How to get rid of old editions

    Some people don't like keeping all those old versions in their database. They believe that they are slowing down their site. This, however, is a myth.

    WordPress developer Mike Little responded in a comment on WPBeginner, "WordPress database queries do not receive revisions, so the number of revisions does not affect query execution speed. The only time revisions are loaded on the page is when editing an individual post. And this does not affect your site's page loading speed.

    However, many people still believe that having a small and lightweight database is a very good thing, and therefore they still prefer to get rid of their old revisions.

    If you are one of them, then one of the three plugins below will help you do this.

    1. Better Delete Revision

    Better Delete Revision deletes old versions of posts and also optimizes your database.

    The plugin page states: "By optimizing and deleting old editions, this plugin will make your database lighter and smaller over the course of its use. Removing old editions and optimizing databases is one of the best things you can do to keep your The blog worked as quickly as possible."

    Take a look at the plugin settings page as well as the uninstallation process.

    Plugin different from Better Delete Revision in that it does not bulk delete your revisions, however, it will give you two features that Better Delete Revision does not have.

    It allows you to first determine how many revisions have been saved.

    And it allows you to delete individual revisions on the edit page.

    3. Revision Cleaner

    Plugin Revision Cleaner allows each user to set a time interval for automatic deletion of his revisions. This can be done on the user profile page.

    Today's article will talk about WordPress revisions.

    WordPress revisions are automatic saving of posts when editing. On the one hand, this is an excellent function: for example, you have been writing an article for more than an hour, when suddenly the electricity in the apartment is turned off, or the browser freezes, or the tab is accidentally closed... When this happened to me for the first time, thoughts immediately came to mind about how I’ll have to type the text again, align the images, in general, do everything all over again, but no such luck! WordPress automatically saved my entire post! You won’t believe how grateful I was to the developers for such a feature.

    But there is also another side to the coin. By default, WordPress revisions are done every 60 seconds and each revision is written to the database. Now calculate how many revisions you have on average per post and multiply by the number of blog posts. Wildly a lot! Half of the database size may consist of revisions. This is exactly what happened to me. See how the database size has decreased after deleting all revisions. Twice!

    How to Disable WordPress Revisions

    For disabling WordPress revisions open the wp-config.php file, it is located in the root of your site.

    We go into it and add the following lines:

    define("WP_POST_REVISIONS", 0);

    The number in parentheses shows how many revisions are allowed for one entry. You can also specify the autosave interval in seconds (default 60).