Created
September 14, 2015 19:36
-
-
Save zealoushacker/9685f91ccfe176d626c4 to your computer and use it in GitHub Desktop.
update-all-thumbs-for-a-given-other-meta_key-in-woocommerce
This file contains hidden or 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
# in WC/WP | |
# provided that we want to update all | |
# thumbnails of all products to a specific thumbnail id (in this case 10759), | |
# where no thumbnail exists, | |
# and where a specific other meta_key is matched (in this case 'attribute_pa_finish') | |
# and where a specific other meta value is matched (in this case 'black-melamine') | |
# this is the fun little query that will do it | |
update wp_4_postmeta as m | |
inner join | |
(select * from wp_4_postmeta | |
where post_id in ( | |
select post_id from wp_4_postmeta | |
where meta_key='attribute_pa_finish' | |
and meta_value='black-melamine' | |
) | |
and meta_key='_thumbnail_id' | |
) as foo | |
on foo.post_id = m.post_id | |
set m.meta_value=10759 | |
where m.meta_key='_thumbnail_id' | |
and m.meta_value=0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment