Drupal – Delete all content nodes of a given type
By David Pratt / Tags: drupal / 6 Comments / Published: 28-07-09
If you have thousands of nodes in your Drupal 6 CMS, there is no easy way from within the admin area to delete large numbers of nodes of a given type. If you rely on the GUI you will end up having to do dozens of “select all, delete” iterations to get through it all.
This sneaky bit of code will delete all records of a particular type (just replace the #### appropriately):
$query = db_query("SELECT n.nid FROM {node} n WHERE n.type = '####'"); while ($n = db_fetch_object($query)) { node_delete($n->nid); }
Careful!
UPDATE:
There is a far better way of doing this: if you activate the Devel module, and then use the following line of code:
//Delete all data of content type "event": devel_generate_content_kill(array('node_types' => array('event')));
woo October 28th, 2011 at 11:43 am
That’s an amazing little firefox extension Nelson, simple way to automate the process of deleting thousands of nodes through views bulk operations or through the normal content management feature.