Created
August 20, 2018 10:58
-
-
Save mmilosheski/65db7c678ee309f0a5dbb4e5d0ec8811 to your computer and use it in GitHub Desktop.
bulk-delete-terms of taxonomy
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
$wpdb->query( "DELETE relations.*, taxes.*, terms.* | |
FROM $wpdb->term_relationships AS relations | |
INNER JOIN $wpdb->term_taxonomy AS taxes | |
ON relations.term_taxonomy_id=taxes.term_taxonomy_id | |
INNER JOIN $wpdb->terms AS terms | |
ON taxes.term_id=terms.term_id | |
WHERE object_id IN (SELECT ID FROM $wpdb->posts WHERE post_type='baby-names-lists')"); | |
$wpdb->query( "DELETE FROM `$wpdb->termmeta` | |
WHERE | |
`term_id` in ( | |
SELECT `term_id` | |
FROM `$wpdb->term_taxonomy` | |
WHERE `taxonomy` in ('baby-names') | |
)"); | |
$wpdb->query( "DELETE FROM `$wpdb->terms` | |
WHERE | |
`term_id` in ( | |
SELECT `term_id` | |
FROM `$wpdb->term_taxonomy` | |
WHERE `taxonomy` in ('baby-names') | |
)"); | |
$wpdb->query( "DELETE FROM `$wpdb->term_taxonomy` WHERE `taxonomy` in ('baby-names')"); | |
$wpdb->query( "DELETE meta FROM $wpdb->termmeta meta LEFT JOIN $wpdb->terms terms ON terms.term_id = meta.term_id WHERE terms.term_id IS NULL"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment