Created
December 18, 2024 11:55
-
-
Save justingreerbbi/7e842ce781c860e6bce240d51a34fb79 to your computer and use it in GitHub Desktop.
Remove a WordPress Taxonomy using MySQL query and WPDB
This file contains 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
global $wpdb; | |
$taxonomy_name = 'taxonomy_name_goes_here'; | |
$wpdb->query( | |
"DELETE FROM {$wpdb->terms} AS t | |
WHERE t.term_id IN ( | |
SELECT tt.term_id FROM {$wpdb->term_taxonomy} AS tt | |
WHERE tt.taxonomy = '{$taxonomy_name}' | |
)" | |
); | |
$wpdb->query( | |
"DELETE FROM {$wpdb->term_relationships} AS tr | |
WHERE tr.term_taxonomy_id IN ( | |
SELECT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} AS tt | |
WHERE tt.taxonomy = '{$taxonomy_name}' | |
)" | |
); | |
$wpdb->query( | |
"DELETE FROM {$wpdb->term_taxonomy} | |
WHERE taxonomy = '{$taxonomy_name}'" | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment