You’ll often find yourself having to delete all content for a particular content type. You may have tested imported content via feeds and you then need to delete what you’ve imported. Or content was created that is no longer required. Manually ticking everything in the content list is fine if you have just a handful of nodes, but if you have a lot of content to delete, it can get very time consuming.
There are a few bulk delete modules available, which will do the job. But if you already have devel installed (highly recommended for any sort of Drupal development), you don’t actually need to install anything else. Devel’s Devel Generate module can delete all content for a content type, or multiple content types. Devel Generate is designed to make it easier to create dummy content when building and testing new sites, and then delete that dummy content. But, even if Devel Generate didn’t create the content, it can still delete it.
The trick is to use the “kill” option . This is what tells devel to delete all content. Normally you’d use kill to delete all dummy nodes that Devel Generate created and then have devel generate a bunch of new dummy nodes. But if all you want to do is delete the nodes and not create any new content (perhaps you want to retest your feed’s import), you can specify 0 as the number of new nodes to create.
drush genc 0 --kill
And if you want to delete all nodes from a particular content type, just specify the content type:
drush genc 0 --kill --types=article
And if you want to delete all nodes from multiple content types:
drush genc 0 --kill --types=article, book
You can also do this in the UI if you’d rather not use Drush. Here are the steps.
- Go to admin/config/development/generate/content
- Select the content type(s) you want to delete
- Tick - Delete all content in these content types before generating new content.
- How many nodes would you like to generate? - set 0
- Click generate
Drupal 7 vs Drupal 8
The process for deleting nodes using Devel generate on Drupal 8 is identical as Drupal 7 for both the Drush and UI method.