Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Retrieve posts with a broken thumbnail (thumbnail set to an attachment that does not exist)
SELECT `wp_posts`.`ID`, `wp_posts`.`post_title`, `b`.`ID` as 'thumbnail'
FROM `wp_posts`
INNER JOIN (
SELECT *
FROM `wp_postmeta`
WHERE `meta_key` = '_thumbnail_id'
) AS a ON `wp_posts`.`ID` = `a`.`post_id`
LEFT JOIN (
SELECT *
FROM `wp_posts`
) AS b ON `a`.`meta_value` = `b`.`ID`
WHERE true
AND `wp_posts`.`post_type` = 'post'
AND `wp_posts`.`post_status` = 'publish'
AND `b`.`ID` IS NULL
GROUP BY `wp_posts`.`ID`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.