Skip to content

Instantly share code, notes, and snippets.

@jamesmorrish
Created August 20, 2013 08:39
Show Gist options
  • Save jamesmorrish/6278797 to your computer and use it in GitHub Desktop.
Save jamesmorrish/6278797 to your computer and use it in GitHub Desktop.
Delete all nodes of type
$node_type = 'product';
// Select the nodes that we want to delete.
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', $node_type, '=')
->range(0,5)
->execute();
$deleted_count = 0;
foreach ($result as $record) {
node_delete($record->nid);
$deleted_count++;
}
// Simple debug message so we can see what had been deleted.
echo "<!-- $deleted_count nodes have been deleted -->";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment