Skip to content

Instantly share code, notes, and snippets.

@crissoca
Forked from pmgarman/delete.sql
Created November 21, 2015 00:54
Show Gist options
  • Save crissoca/dbab5ce28f644bd219be to your computer and use it in GitHub Desktop.
Save crissoca/dbab5ce28f644bd219be to your computer and use it in GitHub Desktop.
How to find and delete orphaned product variations from WooCommerce sites.
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'
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment