Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created February 1, 2017 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/e448ff39fe7333be7346ffe51b0be3fc to your computer and use it in GitHub Desktop.
Save cameronjonesweb/e448ff39fe7333be7346ffe51b0be3fc to your computer and use it in GitHub Desktop.
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