WordPress automatically creates revisions whenever you edit posts, pages, or other content. These revisions act as restore points, allowing you to compare changes and revert to previous versions if necessary.
This feature is particularly useful when multiple people manage website content or when you need to recover an earlier version of an article.
However, on larger websites with frequent content updates, revisions can accumulate quickly and significantly increase the size of the database. Periodically removing old revisions can help reduce database size and improve performance.
Important
This guide is intended for users with basic database administration knowledge.
Before executing any SQL queries:
- Create a complete database backup.
- Verify that you have selected the correct database.
- Test your website after performing any cleanup operations.
Table of Contents
Access phpMyAdmin
- Log in to the mybox Panel.
- Navigate to:
Databases
- Click:
phpMyAdmin
A new browser tab will open with the database login page.
Log In to the Database
Use the database credentials assigned to your WordPress website.
If you do not know the credentials, you can find them in the wp-config.php file located in your WordPress installation directory.
Example:
define('DB_NAME', 'database_name');
define('DB_USER', 'database_user');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'database_host');
By default, the file is located in:
public_html
Open the SQL Query Editor
After logging in:
- Select the WordPress database from the left-hand menu.
- Click the:
SQL
tab at the top of the page.
This will open the query editor where you can execute SQL commands.
Remove WordPress Revisions
Enter the following SQL query:
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';
Click:
Execute
to run the query.
What Does This Query Do?
The query removes:
- Revision entries stored in the
wp_poststable. - Related metadata stored in the
wp_postmetatable. - Associated taxonomy relationships stored in the
wp_term_relationshipstable.
This helps eliminate unnecessary database records created by WordPress revision history.
Benefits of Removing Revisions
Cleaning old revisions can provide several benefits:
- Reduced database size.
- Faster database backups.
- Improved database query performance.
- Reduced storage consumption.
- Easier database maintenance.
These benefits become more noticeable on websites with:
- Large numbers of posts.
- Multiple content editors.
- Frequent content updates.
- Long operating history.
Limiting Future Revisions
To prevent excessive revision growth in the future, you can limit the number of revisions WordPress stores.
Add the following line to your wp-config.php file:
define('WP_POST_REVISIONS', 10);
This example limits WordPress to storing the 10 most recent revisions for each post.
You can adjust the value as needed.
Alternative Cleanup Methods
If you prefer not to work directly with SQL queries, many WordPress optimization plugins include revision cleanup tools, such as:
- WP-Optimize
- Advanced Database Cleaner
- LiteSpeed Cache
- WP Rocket
These plugins can safely remove old revisions through the WordPress administration panel.
Summary
WordPress revisions provide a useful version history for content, but they can significantly increase database size over time.
To remove accumulated revisions:
- Open phpMyAdmin.
- Select your WordPress database.
- Open the SQL tab.
- Execute the revision cleanup query.
Always create a backup before making database changes and verify that your website functions correctly after the cleanup process is complete.