How To Delete WordPress Post Revisions Using fuctions.php File

I was recently messing around with my website’s MySQL database, and I did something new and good. I searched around the internet and there is no script on the internet to delete WordPress post revisions using functions.php file, so I created one. Believe me, it’s easy as making milkshake.

Add following code to your theme’s functions.php file and it’ll delete all the post revision:

global $wpdb;

$wpdb->query( "
DELETE FROM $wpdb->posts
WHERE post_type = 'revision'
" );

[alert style=”red”]Note: Please remove this code immediately after saving your functions.php file. You only need to run this code once, there’s no need to keep this code in your theme.[/alert]