Skip to content

Instantly share code, notes, and snippets.

@jameshiggins
Last active November 29, 2016 23:48
Show Gist options
  • Save jameshiggins/ae402877c107ec5f87a237332e92b5dd to your computer and use it in GitHub Desktop.
Save jameshiggins/ae402877c107ec5f87a237332e92b5dd to your computer and use it in GitHub Desktop.
Select Then Delete WooCommerce orphaned products
ALWAYS BACKUP YOUR DATABASES BEFORE THIS OPERATION
SELECT * FROM `wp_posts` o
LEFT OUTER JOIN `wp_posts` r
ON o.post_parent = r.ID
WHERE r.id IS null AND o.post_type = 'product_variation'
DELETE o FROM `wp_posts` o
LEFT OUTER JOIN `wp_posts` r
ON o.post_parent = r.ID
WHERE r.id IS null AND o.post_type = 'product_variation'
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment