Delete wordpress post revisions to reduce the db size

When you edit wordpress posts it automatically creates revision of the post. This is useful if you wanted to rollback to a previous version of the post.

But a problem with this is it creates a record in database each time. This means it increases your database size. This won’t be a much issue for a small site with few posts. But when you have more posts and if you edit posts very often it will affect a lot for your site in the long run. Sometimes this will increase your site loading time and make the site to perform slowly.

Best thing is to delete the revisions often. You can do this by running a simple mysql query. This is the query for it,

۱ 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)
۵ WHERE a.post_type = 'revision'

This will delete all the revisions as well as the post meta and term relationship records related to them.

If you wish to turn off creating revisions add following code to wp-config.php

۱ define('WP_POST_REVISIONS', false );

Instead turn off revisions if you wish to limit the number of revision created per post, add following code to wp-config.php

۱ define('WP_POST_REVISIONS', 3);

You can modify the number 3 to any number you like. WordPress will keep only that amount of revisions per a post.

If you are not familiar with sql and php there are many plugins that you can use to manage revisions. Here is a better one.

Delete Post Revisions by Donal MacArthur

5 سال پیش

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

این سایت از اکیسمت برای کاهش هرزنامه استفاده می کند. بیاموزید که چگونه اطلاعات دیدگاه های شما پردازش می‌شوند.