Skip to content

Instantly share code, notes, and snippets.

@zerolab
Created June 23, 2010 11:42
Show Gist options
  • Save zerolab/449820 to your computer and use it in GitHub Desktop.
Save zerolab/449820 to your computer and use it in GitHub Desktop.
Mass-deletion of Drupal nodetypes
<?php
/**
* Mass delete nodes of $nodetype
* put the file in the Drupal root and adjust $nodetype and $limit as you like
*/
error_reporting(E_ALL);
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$nodetype = "INSERT_NODETYPE_HERE";
$limit = 100;
$results = db_query("SELECT nid FROM {node} WHERE type='%s' LIMIT %d", $nodetype, $limit);
$count = 0;
while ($result = db_fetch_object($results)) {
node_delete($result->nid);
print 'Deleted node: ' . $result->nid . '<br />';
$count++;
}
print "Total deleted: $count";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment