Applies to: WordPress 7.1.2 (block editor) and WP-CLI
Every time you save or update a post or page, WordPress keeps the previous version as a revision. While you edit, it also makes an autosave every 60 seconds (the default AUTOSAVE_INTERVAL). Revisions let you go back to an older version, but by default WordPress keeps all of them, which slowly grows the database.
Restore an older version
- Open the post or page in the editor.
- In the sidebar, on the Post (or Page) tab, find Revisions and click the number next to it.
- The editor switches to a revision view: move the slider at the top, or pick a version in the sidebar list.
- Click Restore to bring that version back, or Exit to return without changes. The Open classic revisions screen link shows the older side-by-side comparison.
The Revisions row only appears once a post has at least one revision.
Limit how many are kept
Add this to wp-config.php, above the line /* That's all, stop editing! */:
define( 'WP_POST_REVISIONS', 5 );
Or with WP-CLI: wp config set WP_POST_REVISIONS 5 --raw. In our test, a post had 5 revisions; after setting the limit to 3 and saving it again, WordPress deleted the oldest ones and kept 3. The limit is applied to a post the next time it is saved.
define( 'WP_POST_REVISIONS', false ); turns revisions off completely (autosaves still happen). We recommend keeping a few instead.
Delete old revisions with WP-CLI
Back up the database first (wp db export). Then:
wp post list --post_type=revision --format=count wp post delete $(wp post list --post_type=revision --format=ids) --force
If there are no revisions, the second command only prints its usage help, because it gets no IDs. Afterwards you can run wp db optimize to reclaim the space.
Without SSH
Database cleanup plugins can remove revisions from the dashboard. Remove the plugin again when you are done if you don’t need it regularly.
More WordPress fixes: critical error or white screen and change the WordPress salts.