Every time you hit “Save Draft” or “Update” in WordPress, the system silently stores a complete copy of your content as a post revision. On a site with hundreds of posts edited frequently, this adds up fast, bloating your wp_posts table with thousands of unnecessary rows that slow down queries, inflate database backups, and waste storage.
This guide covers three practical approaches to taming WordPress post revisions: limiting how many are kept, disabling them entirely, and cleaning up existing revision bloat safely. We will use wp-config.php constants, PHP filters, raw SQL, and WP-CLI, with safety warnings at every step. If you are working through a broader WordPress maintenance checklist, revision management should be near the top of your list.
How WordPress Post Revisions Work
WordPress stores revisions as rows in the wp_posts table with a post_type of revision. Each revision is a child of its parent post, linked via the post_parent column. WordPress also creates autosaves, a special single revision that gets overwritten every 60 seconds while you edit.
Here is a quick breakdown of how revisions accumulate:
- Every “Update” click creates one new revision row
- Autosaves are stored separately (one per post, overwritten)
- No default limit, WordPress stores unlimited revisions out of the box
- Revisions are never auto-deleted, they persist until you remove them
To see how many revisions your database currently holds, run this SQL query in phpMyAdmin or your database client:
If that number is in the thousands, or tens of thousands, it is time to act.
Understanding the Performance Impact
Post revisions affect WordPress performance in several measurable ways:
- Database size: Each revision duplicates the full
post_contentfield. A 2,000-word post with 50 revisions stores 100,000+ words of redundant content in your database. - Query performance: Queries against
wp_postsscan more rows. Thewp_postmetatable also grows because each revision can carry its own meta entries. - Backup size and duration: Larger databases take longer to back up and restore. For sites on shared hosting with limited storage, this directly impacts costs and reliability.
- Admin editor slowdowns: The block editor loads revision data. Posts with 100+ revisions can noticeably slow down the editing experience, especially on resource-constrained servers.
Cleaning up revisions on a database with 50,000+ revision rows can reduce the wp_posts table size by 40-60% and improve query response times measurably. The exact gains depend on your average post length and how many revisions each post carries.
Method 1: Limit Post Revisions via wp-config.php
Setting a Revision Limit
Open your wp-config.php file (located in the WordPress root directory) and add this line before the /* That's all, stop editing! */ comment:
Here is what different values do:
| Value | Behavior |
|---|---|
true (default) | Unlimited revisions, WordPress default |
false or 0 | Disables revisions completely (autosaves still work) |
5 | Keeps the 5 most recent revisions per post |
10 | Keeps the 10 most recent revisions per post |
-1 | Unlimited revisions (same as true) |
Recommended value for most sites: 3 to 5. This preserves enough history to recover from accidental edits while keeping the database lean.
WP_POST_REVISIONS only affects future saves. Existing revisions beyond the limit are not automatically deleted. You need to clean those up separately (covered in Method 3 below).
Disabling Revisions Entirely
If you do not need revision history at all, for example, on a site where content is managed through version control or staging workflows, you can disable revisions completely:
Method 2: Fine-Grained Control with the wp_revisions_to_keep Filter
The wp_revisions_to_keep filter gives you programmatic, per-post-type control over revision limits. This is more flexible than the wp-config.php constant because you can set different limits for different content types.
Basic Usage
Add this to your theme’s functions.php or, better, a custom site-specific plugin:
Per-Post-Type Limits
This is where the filter becomes genuinely useful. You can keep more revisions for high-value content (like landing pages) and fewer for less critical types:
Disable Revisions for Specific Post Types Only
If you want revisions for posts and pages but not for a custom post type like event:
wp_revisions_to_keep filter takes priority over the WP_POST_REVISIONS constant. If both are set, the filter wins. This is documented in the WordPress Developer Reference.
Method 3: Clean Up Existing Revisions Safely
Limiting future revisions is only half the battle. If your site has been running for months or years without revision limits, thousands of stale revisions are sitting in the database right now. Here is how to remove them safely.
Step 1: Back Up Your Database First
This step is non-negotiable. Before running any deletion query, create a full database backup:
Verify the backup file exists and has a reasonable file size before proceeding. A database with 50,000 posts should produce a backup file at least a few hundred megabytes in size.
Step 2: Check Current Revision Count
Write down this number so you can verify the cleanup worked.
Step 3: Delete Revisions with WP-CLI (Recommended Method)
WP-CLI is the safest cleanup method because it triggers proper WordPress hooks and automatically cleans up associated metadata. The gist below includes both standard deletion and a batch approach for sites with 10,000+ revisions:
Step 4: Delete Revisions with Raw SQL (Faster, Riskier)
For databases with 50,000+ revisions where WP-CLI is too slow, direct SQL queries are significantly faster. However, SQL bypasses WordPress hooks entirely, so you must also clean up orphaned data manually. The gist below includes the main deletion, orphan cleanup, and a batched approach:
wp_ with your actual table prefix if you have changed it from the default. You can find your prefix in wp-config.php under the $table_prefix variable. Running these queries with the wrong prefix will either do nothing or, worse, delete data from unrelated tables.
Step 5: Optimize Database Tables
After deleting thousands of rows, MySQL retains the allocated disk space. Run an optimize command to reclaim it:
On large tables, this operation can take several minutes. Run it during low-traffic hours.
Method 4: Reduce Autosave Frequency
While autosaves do not pile up like revisions (WordPress keeps only one autosave per post, overwriting it each time), the default 60-second interval generates frequent database writes on busy multi-author sites. You can increase the interval:
Add this to wp-config.php alongside your revision settings. A value between 120 and 300 seconds is reasonable for most sites. Do not set it too high, autosaves exist to protect against browser crashes and accidental tab closures.
Complete wp-config.php Configuration Block
Here is a ready-to-use configuration block that combines all the settings covered above. Drop this into your wp-config.php file before the “stop editing” comment:
Automating Revision Cleanup with WP-Cron
For sites that need ongoing maintenance without manual intervention, you can schedule periodic revision cleanups using the WordPress cron system. Add this to a site-specific plugin (not functions.php, theme switches would remove it):
This approach uses $wpdb with the correct table prefix automatically, making it safe across different WordPress installations.
Verifying Your Changes Worked
After implementing any of these methods, verify that your changes are working correctly:
Test the Revision Limit Is Active
- Edit any post and click “Update” 6-7 times (making small changes each time)
- Open the “Revisions” panel in the post editor sidebar
- You should see only 5 revisions listed (if you set the limit to 5)
- The oldest revisions beyond the limit should have been automatically pruned
Plugin Alternatives for Non-Coders
If you prefer a GUI-based approach or you manage a multisite network where editing wp-config.php on every installation is impractical, these plugins handle revision management without code changes:
- WP-Sweep, Lightweight cleanup tool by Lester Chan. Cleans revisions, auto-drafts, orphaned metadata, and more with one click. Uses proper WordPress deletion functions.
- WP-Optimize, Full database optimization suite. Handles revisions plus table optimization, image compression, and caching. Good all-in-one option.
- Advanced Database Cleaner, Granular control with scheduling. Lets you clean specific revision groups and set automated cleanup schedules.
That said, the manual methods described in this guide give you complete control with zero plugin overhead. For a single site, wp-config.php constants plus occasional WP-CLI cleanup is the most efficient approach.
Troubleshooting Common Issues
Revisions Still Being Created After Setting WP_POST_REVISIONS to 0
A plugin or theme may be overriding the constant via the wp_revisions_to_keep filter. Debug with this snippet:
If the logged value is not 0, something is overriding your setting. Check active plugins, some page builders and revision-management plugins apply their own filters.
WP_POST_REVISIONS Constant Has No Effect
The constant must be defined before WordPress loads its core files. Make sure it appears in wp-config.php above the /* That's all, stop editing! Happy publishing. */ line. If it is placed after require_once ABSPATH . 'wp-settings.php';, WordPress has already loaded and the constant is ignored.
SQL Query Times Out on Large Databases
If your DELETE query times out, process in smaller batches and add a brief pause between runs:
Summary and Recommended Configuration
For most WordPress sites, this combination delivers the best balance of safety and performance:
- Set
WP_POST_REVISIONSto 5 inwp-config.php, enough history for recovery, lean enough for performance - Use the
wp_revisions_to_keepfilter if you need different limits per post type - Clean up existing revisions with WP-CLI for safety, or raw SQL for speed on very large databases
- Optimize tables after cleanup with
wp db optimize - Set
AUTOSAVE_INTERVALto 180 to reduce unnecessary database writes - Schedule periodic cleanups via WP-Cron or a maintenance plugin for ongoing hygiene
Post revisions are a genuinely useful safety feature, they have saved countless hours of lost work. But left unchecked, they silently degrade database performance over months and years. A few minutes of configuration gives you the best of both worlds: content recovery when you need it, and a clean, fast database the rest of the time.
This is article 2 of 8 in our Database Optimization series on TweaksWP. Next up: cleaning orphaned postmeta and expired transients.
database cleanup post revisions wp_posts table WP-CLI wp-config.php
Last modified: March 26, 2026