7.x node.module node_delete_multiple($nids)

Deletes multiple nodes.


$nids: An array of node IDs.

4 calls to node_delete_multiple()
BookTestCase::testBookDelete in modules/book/book.test
Tests the access for deleting top-level book nodes.
node_delete in modules/node/node.module
Deletes a node.
node_multiple_delete_confirm_submit in modules/node/node.admin.inc
Form submission handler for node_multiple_delete_confirm().
node_user_delete in modules/node/node.module
Implements hook_user_delete().


modules/node/node.module, line 1244
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.


function node_delete_multiple($nids) {
  $transaction = db_transaction();
  if (!empty($nids)) {
    $nodes = node_load_multiple($nids, array());
    try {
      foreach ($nodes as $nid => $node) {

        // Call the node-specific callback (if any):
        node_invoke($node, 'delete');
        module_invoke_all('node_delete', $node);
        module_invoke_all('entity_delete', $node, 'node');
        field_attach_delete('node', $node);

        // Remove this node from the search index if needed.
        // This code is implemented in node module rather than in search module,
        // because node module is implementing search module's API, not the other
        // way around.
        if (module_exists('search')) {
          search_reindex($nid, 'node');

      // Delete after calling hooks so that they can query node tables as needed.
        ->condition('nid', $nids, 'IN')
        ->condition('nid', $nids, 'IN')
        ->condition('nid', $nids, 'IN')
        ->condition('nid', $nids, 'IN')
    } catch (Exception $e) {
      watchdog_exception('node', $e);
      throw $e;

    // Clear the page and block and node_load_multiple caches.


pillarsdotnet’s picture

The number of nodes that can be loaded into memory in a single query is limited by the PDO layer, the database driver, configuration details, and of course, available memory. Passing too large an argument array to this function can result in the cryptic error message General error: 1 too many SQL variables.

A documentation bug has been posted to note the limited argument length.

aaronaverill’s picture

Arguably it should just work with unlimited arguments. It would be trivial to loop through mod N times and call each node delete in say... blocks of 25, or 50, or 100 nids. Why not ?

camerongreen’s picture

Would be nice to have an optional second argument that allows this for those performing mass deletes

janter’s picture

A boolean return would be nice.

charlie-s’s picture

It throws an Exception, so you would put this inside of a try/catch block.

delaBruyne’s picture

I user this hook to delete all nodes from a certain content type :

* Delete nodes and content types.
function lth_configuration_update_7011() {
  $types = array(
  foreach($types as $type) {
    // First, delete nodes
    $results = db_select('node', 'n')
                ->fields('n', array('nid'))
                ->condition('type', $type)
    foreach ($results as $result) {
      $nids[] = $result->nid;
    if (!empty($nids)) {
      drupal_set_message(t('%count nodes has been deleted.', array('%count' => count($nids))));
    // Then, delete content type
    if (node_type_load($type)) {
      variable_del('node_preview_' . $type);
      drupal_set_message(t('%type content type has been deleted.', array('%type' => $type)));

See https://gist.github.com/delaBruyne/ced040887c1971a978ca

MacSim’s picture

When you select ONLY one field and expect to get multiple rows, you can avoid these lines

    foreach ($results as $result) {
      $nids[] = $result->nid;

using the following :

$nids = $results->fetchCol();
nikhileshpaul’s picture

$getabs = db_select('node', n)->fields('n', array(nid))->condition('type', 'getabstract')->execute()->fetchCol();

Above code didn't work for me. Had to resort to node_delete as below

$getabs = db_select('node', n)->fields('n', array(nid))->condition('type', 'getabstract')->execute()->fetchCol();

foreach($getabs as $getab) {