Posted on

Example to bulk delete/clean WordPress post meta data MySQL query

SELECT 
COUNT(DISTINCT meta_id)
FROM
wp_postmeta m
LEFT JOIN
wp_posts p ON m.post_id = p.id
WHERE
p.id IS NULL;

DELETE m FROM wp_postmeta m
LEFT JOIN
wp_posts p ON m.post_id = p.id
WHERE
p.id IS NULL;
Leave a Reply

Your email address will not be published. Required fields are marked *