Delete many thousands of nodes

We recently had reason to delete over a thousand Drupal 6 nodes of the same type,
but we wanted to leave all other content on the site intact.

What do you do when you want to delete multiple nodes from a drupal site?
You go to admin » content and then delete nodes one by one or delete up to 50 nodes at one time?

In this example we will delete all nodes of a particular type (page), It is quick way to delete


$node_type = 'image_album'; //fetch the nodes we want to delete
$result = db_query("SELECT nid FROM {node} WHERE type='%s'",$node_type);
while ($row = db_fetch_object($result)){
node_delete($row-?>nid);
$deleted_count+=1;
}
//simple debug message so we can see what had been deleted.
drupal_set_message("$deleted_count nodes have been deleted");

No comments: