Last active
February 8, 2017 15:45
-
-
Save salase/70585b95d73c7bef8dd4d04d15947b3d to your computer and use it in GitHub Desktop.
Wordpress: Assign post's featured images via DB
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
-- Substitute # for site ID: | |
insert into wp_#_postmeta (post_id,meta_key,meta_value) | |
select p.id,'_thumbnail_id',min(a.id) | |
from wp_#_posts p | |
join wp_#_posts a on (a.post_type = 'attachment' and a.post_parent=p.id) | |
where p.post_type = 'post' | |
and p.id not in (select post_id from wp_#_postmeta where meta_key='_thumbnail_id') | |
group by p.id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment