This is for people who are good with MySQL queries. I'm using phpMyAdmin locally to try to optimize an old WordPress & Woocommerce site which has gone through a couple of iterations over the years.
I should have ~2000 orphaned image attachments in the
wp_posts table and each should have a couple of related entries in the
wp_postmeta table. I'm trying to clear them out completely.
I've figure out how to locate these image attachments:
they share this in common with ~160 live products:
wp_posts.post_type = 'attachment' AND wp_posts.post_parent = 0 AND wp_postmeta.post_id = wp_posts.ID
but they do not possess a
meta_key = '_thumbnail_id'row in
wp_postmeta, only the live products do.
I just don't know how to combine those two statements into an SQL query to find these old products which do not have the
_thumbnail_id row. I've tried some combinations of
NOT EXISTS to no avail, but I don't know if I'm using it correctly or if I need to use another method.
My approach (maybe you have a better one?) is to locate and delete those products from
wp_posts based on these two conditions, and then delete their orphaned metadata from
wp_postmeta (which should be easy enough for me).