Deleting nodes tagged with a taxonomy term

Occasionally, we find ourselves with a area of the website that we no longer use and can safetly delete. Normally, it’s a very small area of the site, and one of our content administrators will delete the nodes, then I’ll remove the files and the taxonomy term associated with the nodes (we use Drupal’s taxonomy module to regulate permission and to generate URLs).

But today we had the opportunity to delete several hundred nodes all at once, under about a dozen taxonomy terms. Time to script it.

After backing up your database, you can run this by specifying the $termid that you want to delete, then calling drush scr ~/path/to/script/delete_term_and_nodes.php.

©2022 Kyle Schmidt some rights reserved