Vincent's blog

Clean WordPress Database

To clean up your WordPress database, you can use three useful SQL queries. It's important to back up your database before proceeding.

To delete orphaned post meta, use this query:

DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT ID FROM wp_posts);

To delete post meta from revisions, use this query:

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'revision');

Finally, delete the revisions from your database:

DELETE FROM wp_posts WHERE post_type = 'revision';

#wordpress