Last active
July 4, 2023 13:16
-
-
Save FrancoStino/1eab06162ad18286ba0ced33471030bf to your computer and use it in GitHub Desktop.
Query SQL to delete, remove and clean all product, term, tag, attribute and categories - Woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'); | |
DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'; | |
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy); | |
DELETE relations.*, taxes.*, terms.* | |
FROM wp_term_relationships AS relations | |
INNER JOIN wp_term_taxonomy AS taxes | |
ON relations.term_taxonomy_id=taxes.term_taxonomy_id | |
INNER JOIN wp_terms AS terms | |
ON taxes.term_id=terms.term_id | |
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product'); | |
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product'); | |
DELETE FROM wp_posts WHERE post_type = 'product'; | |
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL; | |
delete from `wp_termmeta` | |
where | |
`term_id` in ( | |
SELECT `term_id` | |
FROM `wp_term_taxonomy` | |
WHERE `taxonomy` in ('product_cat', 'product_type', 'product_visibility') | |
); | |
delete from `wp_terms` | |
where | |
`term_id` in ( | |
SELECT `term_id` | |
FROM `wp_term_taxonomy` | |
WHERE `taxonomy` in ('product_cat', 'product_type', 'product_visibility') | |
); | |
DELETE FROM `wp_term_taxonomy` WHERE `taxonomy` in ('product_cat', 'product_type', 'product_visibility'); | |
DELETE meta FROM wp_termmeta meta LEFT JOIN wp_terms terms ON terms.term_id = meta.term_id WHERE terms.term_id IS NULL; | |
DELETE FROM wp_woocommerce_attribute_taxonomies; | |
DELETE FROM wp_woocommerce_sessions; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment