1

I'm trying to clean and optimize my WordPress database, and I'm wondering if it's safe to write a MySQL script that would purge/delete all revision post types from the wp_posts table and run it periodically via cron job.

Would it also be safe to then reorder post IDs by post date to reflect the now-deleted revisions being gone?

1

IF you want, you can disable revisions in first place (No need to run CRON then)

To disable them go to wp-config.php and add this line:

define('WP_POST_REVISIONS', false );

Or to limit to 10 revisions

define('WP_POST_REVISIONS', 10);

And to delete all current revisions you can run this SQL query:

DELETE FROM wp_posts WHERE post_type = "revision";

Here seems to be quite decent plugin to do that for you (It does a lot more too) https://wordpress.org/plugins/rvg-optimize-database/

Also DO backups

And another SO thread: Safest way to bulk delete post revisions

  • I don't want to disable revisions entirely because we do need them when writing articles. Thanks for the link to that other SO thread though. Do you know if there would be any orphaned data I would have to worry about? And what about reordering the IDs? – Mike Dec 12 '16 at 20:34
  • There might be some orphaned data, depending on your page structure (Tags that are no longer used or custom fields etc). You can delete them with LEFT JOINs. Code is in other SO thread, you can read it from there But about IDs, no need to reorder them. DB can nicely handle them. – Margus Kevin Dec 13 '16 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.