Andrej229
Andrej229

Reputation: 69

Delete woocommerce products without featured images

I have more than 1500 products without featured images. I have to delete it. I found a query to get list of this products:

 select ID FROM wp_posts WHERE ID NOT IN (select post_id from wp_postmeta WHERE meta_key="_thumbnail_id") AND post_type="product"

and I found this plugin https://pl.wordpress.org/plugins/woocommerce-products-without-featured-images/ but I can't delete product from it...

both things do the same thing

Can you hint how can I remove these products?

Upvotes: 4

Views: 4261

Answers (2)

gezanoletti
gezanoletti

Reputation: 147

I suggest update products to trash status. In this way, you can use the Wordpress formal mechanism to delete those products.

Based on @kumar-rakesh answer, I used this query:

UPDATE wp_posts SET post_status =  "trash" WHERE ID NOT IN (
    SELECT post_id
    FROM wp_postmeta
    WHERE meta_key =  "_thumbnail_id"
)
AND post_type =  'product';

I did it with 4500 products and it was successful.

Hope this help!

Upvotes: 4

Kumar Rakesh
Kumar Rakesh

Reputation: 2708

These are two query... It will be working fine...

Basically these query use only for delete the woocomerce product..

DELETE FROM wp_postmeta
WHERE post_id IN(SELECT ID FROM wp_posts WHERE ID NOT IN (select post_id from wp_postmeta WHERE meta_key="_thumbnail_id") AND post_type = 'product');

DELETE FROM wp_posts WHERE ID NOT IN (select post_id from wp_postmeta WHERE meta_key="_thumbnail_id") AND post_type = 'product';

Upvotes: 1

Related Questions