Created
October 27, 2020 22:35
-
-
Save vpnwall-services/8f300373121cf4ddcac922e1a2acee26 to your computer and use it in GitHub Desktop.
[MYSQL Find orphaned images] Mysql find orphaned images #mysql #find #orphaned #images
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 | |
* | |
FROM | |
wp_posts i | |
WHERE | |
i.post_type = 'attachment' | |
AND | |
NOT EXISTS (SELECT * FROM wp_posts p WHERE p.ID = i.post_parent) | |
AND | |
NOT EXISTS (SELECT * FROM wp_postmeta pm WHERE pm.meta_key = '_thumbnail_id' AND pm.meta_value = i.ID) | |
AND | |
NOT EXISTS (SELECT * FROM wp_posts p WHERE p.post_type <> 'attachment' AND p.post_content LIKE CONCAT('%',i.guid,'%')) | |
AND | |
NOT EXISTS (SELECT * FROM wp_postmeta pm WHERE pm.meta_value LIKE CONCAT('%',i.guid,'%')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment