How to delete old post revisions in WordPress. How to disable and remove WordPress editions. How to get rid of old editions

💖 Do you like it? Share the link with your friends

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 correspond 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 at WordPress installation you specified a prefix other than “wp_” for the database tables, 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 into the SQL query input field next line:

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 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 further limit the number of copies in different types posts 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.

Change history in WordPress is a convenient functionality that exists in WordPress. It was highly appreciated by content authors who regularly publish their materials. Often, in the process of editing a record, you can make accidental errors or typos. For example, you accidentally deleted part of your entry. It is possible to return this: thanks to revisions, you can always roll back to one of the versions of the recording.

In this article, we'll explain how WordPress's change history functionality works, what types of content you can use it with, and how to get the most out of it.

Change History in WordPress: What is it?

Did you know that WordPress automatically saves all the changes you make to your posts? You can undo these changes and go back to more early version at any given time. This functionality is called revisions (versions). It was introduced back in WordPress 2.6.

With this feature, WordPress will save a post as a revision whenever you click on the “Save as Draft” button or every time automatic saving records. The auto-save feature is activated every 60 seconds - this is a special revision that is replaced with new auto-save versions.

It's worth noting that there is only one autosave available for any given post. The auto-save feature is especially useful in situations where your browser crashes or your power goes out. In this case, if you go back to editing the post, WordPress will show you a notification that you have a backup copy of your post along with a link to restore the content.

How to Work with Change History in WordPress

As you can see from the screenshot below, revisions are located in the Publish section of the post editing screen. You can also display revisions in the post editor by clicking Screen Options and selecting Revisions.

If you click the Browse link, you will be taken to the Revisions page. Here you can see the changes related to each version - to do this, use the slider at the top of the screen. You can also use the Previous and Next buttons. There is functionality for comparing two revisions. The window will indicate what was added, what remained unchanged, and what was removed.

What you can do with revisions: you can either restore the revision or leave the entry as is. If you want to restore a specific revision, you can do this by clicking the Restore this revision button. The Return to post editor link will allow you to return to your post without making any changes.

What types of content do revisions support?

WordPress Revision History works for all posts and pages on your site, as well as custom post types such as Portfolio and Testimonials (added by Jetpack).

If you are using a theme that has its own set of custom post types (for example, portfolio, employees, recommendations, etc.), versions will not be enabled by default (exception: the theme author added support for them). In this case, you can enable revisions yourself using the following code:

$supports = array("title", "editor", "revisions");

The code for custom post types is usually located in the functions.php file. Place a line above the line that starts with register_post_type.

Now let's look at how to benefit from version history.

Enable or completely disable revisions

By default, revision functionality is automatically enabled for every WordPress build. If you don't have the Revisions option in the post editor and you've made changes to your post, then revisions may have been disabled at the configuration level.

You can enable revisions manually by adding the following line to your wp-config.php file:

Define("WP_POST_REVISIONS", true);

You can also disable revisions completely by setting them to false:

Define("WP_POST_REVISIONS", false);

We limit the number of available revisions

If you want to limit the number of revisions available per post or page, you can do so with the following code in your wp-config.php file:

Define("WP_POST_REVISIONS", 5);

As a result, you will get a maximum of 5 revisions for each entry except the autosaved version. This is useful if your hosting is limiting the size of your database or if you think you are not using revisions very often.

Manage revisions on a per-entry basis

If you're willing to do some extra coding, you can do this to limit the number of revisions for each selected entry. To do this, use the wp_revisions_to_keep filter. This is what the code will look like:

Add_filter("wp_revisions_to_keep", "filter_function_name", 10, 2); function filter_function_name($num, $post) ( return $num; )

Here we pass a WP_Post object that represents the target post and the required number of versions.

Revision management plugins

As you can guess, there are many plugins for version control in WordPress. You can use the following plugins to clean up old revisions and enable them for custom post types. We've selected the top rated plugins to help you improve your revision control in WordPress.

Optimize Database After Deleting Revisions

Plugin for cleaning up unnecessary revisions and optimizing the database. Main functions:

  • Delete revisions for posts, pages, and custom post types.
  • Selecting the number of revisions to save.
  • Removing spam comments and unused tags.
  • Removing pingbacks and trackbacks.
  • Optimizing database tables.
  • Etc.

The plugin is compatible with multisites. It supports periodic cleaning runs.

WP Revisions Control

A simple plugin to configure how many revisions WordPress can save for each post and page. Once you activate the plugin, go to Options - Writing to determine how many revisions to store for each post type.

Relatively new plugin, which improves audit management. WordPress will only save revisions if the title, content, or quote has changed. If you modified the author of a post or changed the permalinks for a post, this will not create a revision. This is the advantage of this plugin.

It adds the following fields to the revision system:

  • The Author
  • Post Date
  • Permalink
  • Post Status
  • Post Password
  • Comment Status
  • Ping Status
  • Post/Page Parent
  • Menu Order

The plugin is very convenient for blogs with multiple authors and careful control over revisions in posts.

Another plugin for managing revisions. It allows you to limit the number of revisions for any custom post type.

Other options:

  • Disabling revisions.
  • Limiting post revisions for the entire site, for each type of post, for each individual post
  • Deleting revisions in bulk or individually

Following the departing train called “all versions of WordPress up to 5.0,” I am writing this belated article about revisions or editions of WordPress. Why late? Because the WordPress revisions system will not work with the Gutenberg editor.

The WordPress revisions system

A frequently encountered name for what I want to write about is WordPress revisions. In Russian, it would be more correct to call this system function “WordPress Editions”. This is exactly how this function is translated in the console. The native name of this functionality is “The revision system”, which we translate as “Revision System”. I will call this system function as WordPress editions.

So, WordPress editions are copies of articles saved in the database that the administrator enters into the field text editor systems.

Articles can be included in WordPress editions either after clicking the “Save” button in the editor or as a result of autosaving. Revisions of articles and pages are remembered by date and time.

Autosaving an article is automatic storage of material by the system, without the desire of the administrator. Autosave occurs periodically, every 2 minutes. Each subsequent copy overwrites the previous one. In the editor’s list, this copy is marked “Auto-save” (see screenshot below).

The more you work in the editor, the more autosaved copies will be in your site's database. If you add to them copies of saves made manually, then the garbage nature of this “Revision System” becomes obvious. More on this below.

WordPress Edition Settings and Management

Let's see how this tool generally works. We’ll look at all the possibilities on the “Edit Post” tab, the administrative part of the site. It works the same way in the page editor.

Attention! There are NO edit fields on the folds for adding records and adding pages.

Settings

To disable viewing saved revisions of an article (pages), which is enabled by default, go to the “Settings” button in the upper right corner of the “Edit Entry” page.

Here, traditionally, blocks are removed (added) by highlighting a check, without saving changes.

Control

The included Revisions block is at the bottom of the page. This is what he looks like. There shouldn’t be so many saved records of published material on a working website; it’s garbage and needs to be cleaned up.

  • As you can see, the ruler with the slider is all copies. The slider can be moved, calling one or another copy.
  • There are Previous and Next buttons, I don’t think there’s any need to explain their purpose.
  • The “Compare any two editions” checkbox is not highlighted; in the main fields we will see a comparison of the selected copy and the latest version of the text.
  • If you select the “Compare any two editions” checkbox, you can compare any two saved copies by calling them with the slider. In the main field in the comparison mode we see the texts of the two compared versions of the flock (pages).

For those interested in the original sources, there is a Help button that will give you a link to the WordPress.org Revisions page. The circle is closed, and we understand why this feature is called WordPress revisions.

Revisions are stored as child elements material. By default, the system tracks changes in title, author, content and announcement.

How to disable

By default, the system saves all revisions of both options (regular and auto). If you need them (revisions), you can limit them. To do this, in your wp-config file working theme enter the line:

define("WP_POST_REVISIONS", X);

Meaning X change to:

  • Zero (0) if we do NOT want to save anything;
  • -1, if we want to return everything as it was, by default;
  • Any number to order the number of saved copies you need.

Don’t forget to check the presence of the wp-config file before reacting backup copy site. Or at least make a copy of the file before editing.

Opinion. I don't know why you should disable saving copies. Autosave has helped me out dozens of times when the connection with the server has been lost. It's better to clean them.

Cleaning copies

I repeat, revisions or editions of WordPress are technical garbage, which after the release of the site must be removed and ensure that it does not accumulate.

This can be done using cleaning plugins. About them in detail and. Or for fans, do everything manually, go to



tell friends