I am trying to create a SQL Query that will output the Woocommerce products in my MySQL Database that do not have a featured image assigned to it. As Woo is based on WordPress, I’m not sure where to get the information from but it looks as if I will need to join some tables up.
Has anyone out there had experience with this? I have 500 products and all need to have a Featured Image. I am going through them randomly and assigning each product one, but I need to see how many are left to do and which ones need to be done.
I am unable to sort the Products by Featured Image in the Woocommerce backend so I am hoping it can be achieved via SQL Query.
It looks as if I have found the right query. It joins some tables to give me a list of all products and featured images. I can then sort this list and see what products have NULL Featured Images. The SQL Query I used is below in case it helps somebody:
SELECT p.ID, p.post_title, pm.*
FROM wp_posts p
LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id
AND pm.meta_key = '_thumbnail_id'
WHERE p.post_type IN ( 'product' )
This would be my query. It will return all post id’s ( same as product id’s ) that have no image
Create a View called
Products_List
:Then create another query using
Products_List
above:Another possibility that does not use a NOT IN :
is possible whith sku ? ( no only id)
Simple as that. The following sql returns sku of all products with the default woocommerce image (means all products without image):