Created
February 1, 2017 01:49
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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