SQL delete orphaned post meta data

When using lots of plugins and different themes or when testing your own custom made theme or plugin, a lot of post meta can remain in your database that is not linked to a post. By applying the following query to your database, you can delete all meta data that is no longer linked to a post.

DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL

Leave a reply

Feel free to ask questions or make comments.

Comments

    No comments yet..