Last active
August 29, 2015 14:03
-
-
Save aschanMarcus/e903b3fa8df7ea6005c8 to your computer and use it in GitHub Desktop.
Delete unused taxonomy terms
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
| <?php | |
| $field = 'VOCABULARY_MACHINE_NAME'; | |
| // Search for unused taxonomy terms. | |
| $query = db_query('SELECT DISTINCT field_' . $field . '_tid FROM field_data_field_' . $field . ' WHERE field_' . $field . '_tid NOT IN (SELECT tid FROM taxonomy_term_data)'); | |
| $results = $query->fetchCol(); | |
| // Output results with devel. | |
| dpm($results); | |
| // Delete unused taxonomy terms. | |
| foreach ($results as $result) { | |
| db_delete('field_data_field_' . $field) | |
| ->condition('field_' . $field . '_tid', $result) | |
| ->execute(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment