Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zealoushacker/9685f91ccfe176d626c4 to your computer and use it in GitHub Desktop.
Save zealoushacker/9685f91ccfe176d626c4 to your computer and use it in GitHub Desktop.
update-all-thumbs-for-a-given-other-meta_key-in-woocommerce
# 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