Skip to content

Instantly share code, notes, and snippets.

@jarodthornton
Created September 16, 2021 16:33
Show Gist options
  • Save jarodthornton/f3a2a389722f02c1f5819a2363f3b2bc to your computer and use it in GitHub Desktop.
Save jarodthornton/f3a2a389722f02c1f5819a2363f3b2bc to your computer and use it in GitHub Desktop.
WooCommerce Clear Product Database
DELETE relations.*, taxes.*, terms.*
FROM wpa12_term_relationships AS relations
INNER JOIN wpa12_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wpa12_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wpa12_posts WHERE post_type='product');
DELETE FROM wpa12_postmeta WHERE post_id IN (SELECT ID FROM wpa12_posts WHERE post_type = 'product');
DELETE FROM wpa12_posts WHERE post_type = 'product';
DELETE a,c FROM wpa12_terms AS a
LEFT JOIN wpa12_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wpa12_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag';
DELETE a,c FROM wpa12_terms AS a
LEFT JOIN wpa12_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wpa12_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_cat'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment