Last active
April 21, 2017 07:35
-
-
Save michael-picard/d2b3d00c0eecfc3e110be791cc367996 to your computer and use it in GitHub Desktop.
This query is looking for the image id attached at the beginning of a post and set it as featured image of the post.
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
INSERT INTO wp_postmeta (post_id, meta_key, meta_value) | |
SELECT ID, '_thumbnail_id', substr(post_content, locate('wp-image-', post_content) + 9, 4) FROM wp_posts AS p | |
LEFT JOIN (SELECT * FROM wp_postmeta WHERE meta_key = '_thumbnail_id') AS m ON p.ID = m.post_id | |
WHERE p.post_type = 'post' AND p.post_status = 'publish' AND left(p.post_content, 100) LIKE '%wp-image-%' AND | |
meta_value IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment