I have several thousand nodes of a particular content type. Using the web interface (example.com/admin/content), I can only delete about 50 at a time. How can I quickly delete them?


16 Answers 16


There is a module for that (TM).

See Bulk Delete.

That will use the Batch API to delete the nodes to avoid timeout or memory issues when deleting thousands of nodes with a single call to node_delete_multiple().

Bulk Delete is an abandoned module. See for alternatives:

  • Wow, I completely missed this one. Good find.
    – Greg
    Mar 9, 2011 at 16:38
  • 4
    One other method, that could be useful if you're doing more than a simple content type filter, is to use Views Bulk Operations: drupal.org/project/views_bulk_operations Mar 9, 2011 at 18:11
  • Bulk Delete module is abandoned now. It is suggested there to use Views Bulk Operations.
    – LLub
    Dec 13, 2011 at 14:48

In Drupal 8 one way is use the entityQuery() method with the EntityStorageInterface::delete() method:

$result = \Drupal::entityQuery("node")
    ->condition("type", "YOUR_CONTENT_TYPE_NAME")
    // If the update is being executed via drush entityQuery will only
    // return the content uid 0 have access to. To return all set
    // accessCheck to false since it defaults to TRUE. 

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
$entities = $storage_handler->loadMultiple($result);

If you need to apply other filters/conditions you can check the QueryInterface interface page

EDIT (Other way, thanks to @4k4):

$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
$entities = $storage_handler->loadByProperties(["type" => "YOUR_CONTENT_TYPE_NAME"]);

If you want to test the code you can use:

drush php-eval '$storage_handler = \Drupal::entityTypeManager()->getStorage("node"); $entities = $storage_handler->loadByProperties(["type" => "article"]); $storage_handler->delete($entities);'

This will delete all your articles.

  • This is not correct, delete() expects loaded entities, not ID's, which is what entity query returns. Instead of a non-descriptive $result, use $ids or $nids and then $storage->delete($storage->load($ids)).
    – Berdir
    Dec 30, 2016 at 22:22
  • @Berdir thanks, I will test the code again, maybe this problem was introduced in one edit Dec 30, 2016 at 22:23
  • @Berdir I update the answer and I test the code and it works, the problem was introduced in one edit. Dec 30, 2016 at 22:31
  • 2
    @AdrianCidAlmaguer, you could replace the query with $entities = $storage_handler->loadByProperties(['type' => 'YOUR_CONTENT_TYPE_NAME']);
    – 4uk4
    Dec 30, 2016 at 22:59
  • 2
    Recently used this in an update hook, it's worth noting that if you use entityQuery you should set the accessCheck on the statement. Otherwise if you run it in drush, by default accessCheck is set to true and any nodes that uid 0 does not have access to will not be returned.
    – awm
    Aug 22, 2018 at 16:07

Looking at the Devel Generate module for inspiration, here is its "content kill" function devel_generate_content_kill:

function devel_generate_content_kill($values) {
  $results = db_select('node', 'n')
              ->fields('n', array('nid'))
              ->condition('type', $values['node_types'], 'IN')
  foreach ($results as $result) {
    $nids[] = $result->nid;

  if (!empty($nids)) {
    drupal_set_message(t('Deleted %count nodes.', array('%count' => count($nids))));

So I would try either using Devel Generate to delete all nodes but create no new ones, or use example.com/devel/php to call devel_generate_content_kill(array('node_types' => array('my_node_type'))); directly.


If you want to do it purely through the UI, you can use the devel_generate module.

  1. Navigate to the "Generate Content" menu in "Configuration" (admin/config/development/generate/content).
  2. Select the content types you want to delete.
  3. Make sure the checkbox next to "Delete all content in these content types before generating new content" is checked.
  4. Set the number of nodes you'd like to generate to "0".

This way, no nodes will be generated and all nodes of the selected types will be deleted.


You can do this is in Drupal 7 using the Execute PHP Code part of the Devel module by entering:

$result= db_query("SELECT nid FROM {node} AS n WHERE n.type = 'TYPE'");
foreach ($result as $record) {
  • 1
    This will execute very slowly, if you need to delete thousands of nodes it's better to use a method which uses the batch API such as VBO. Mar 14, 2017 at 15:47

Create a file with below code in root of drupal installation and execute the file.

  require_once './includes/bootstrap.inc';

  $aquery= db_query("SELECT nid FROM {node} AS n WHERE n.type = 'company'");
  while ($row = db_fetch_object($aquery)) {
  • 1
    db_fetch_object is not part of D7 database api.
    – ya.teck
    Dec 25, 2013 at 8:45

Do this in terminal, if you use Drush and the delete all module:

 drush delete-all [content-type-machine-name]

 drush delete-all article             Delect all article nodes.
 drush delete-all all                 Delete nodes of all types.
 drush delete-all --reset             Delete nodes of all types, and reset node, revision and comment counters.
 drush delete-all users               Delete users.

 --reset                              Reset counter for node, revision and comment tables.
 --roles                              pick roles
  • The drush command doesn't work when I use a subsite: drush -l my_site delete-all-delete-content -y but deleting from the ui works >> /admin/content/delete_content. Mar 16 at 8:56

Views Bulk operations provides a BatchAPI enabled, configurable node admin screen that allows filtering by type, selection of all nodes matching your search criteria, etc.

That's my hands-down solution in Drupal 6 - besides batch delete, you can bulk-edit nodes and do a bunch of other stuff.

It looks like the Drupal 7 version isn't ready yet - but I'd be watching that module for a D7 release.


With Devel module, using drush:

drush genc 0 --types=article --kill

Or in UI as explained here: http://befused.com/drupal/delete-nodes-devel

  • It's the Devel sub-module devel_generate that needs to be enabled. And for multiple types it's drush genc 0 --kill --types="article, page"
    – leymannx
    Nov 21, 2018 at 21:39

Another snippet is:

$query = db_query("SELECT n.nid FROM {node} n WHERE n.type = 'TO_BE_DELETED'"); 
while ($n = db_fetch_object($query)) 

where TO_BE_DELETED is the content type to be deleted.

  • 3
    It should be noted that works for Drupal 4.6, 5, and 6 only. The Drupal 7 version is db_delete('node')
    – Greg
    Mar 10, 2011 at 4:44

I use Delete all module, it works fine with D8 and provides very useful drush commands. For example, to delete all content of the article content type:

drush delete-all article  
  • 1
    Does this work with D8? I enabled the module but I get The drush command 'delete-all article' could not be found. I also cleared the drush cache Jan 11, 2017 at 14:39
  • @YassinTahtah I have this same issue.
    – dmgig
    May 13, 2020 at 20:06

You can try Delete all module, navigate to 'admin/content/delete_content' and you will be presented with a form for deletion of content belonging to certain content types.



If you have Migrate module enabled you can use:

$ drush migrate-wipe <content-type>

See Typical migrate commands using Drush.


This module is used to delete all content and/or users from a site. This is mainly a developer tool, which can come in handy in several case


as will as the Bulk Delete module will delete any nodes of a certain node-type using the batch api. It is advised to use the Views Batch Operations module (VBO) for a small number of nodes. But if you have to delete 10.000 nodes this module might be a better option.



Delete all nodes of content type programmatically here is a helper function:

function _delete_all_nodes_of_type($type = '') {
  // Return all nids of nodes of type.
  $nids = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('n.type', $type)
    ->fetchCol(); // returns an indexed array
  if (!empty($nids)) {
    drupal_set_message(format_plural(count($nids), count($nids) . ' node Deleted.', count($nids) . ' nodes Deleted.'));


I ended up using db_delete, no modules required:

    ->condition('type', 'MY_CONTENT_TYPE')

Edit/Warning: See Berdir's comment below. This method does not clean up all data related to the nodes.

  • 3
    The problem with this approach is that other modules are not able to react and delete their information too. Depending on the content type, there is node specific information in the content_type table of that node, fields, taxonomies (a field too, actually), comments and so on. So you possibly end up with a lot of stale information in your database.
    – Berdir
    Mar 9, 2011 at 17:47
  • @Berdir - Interesting. Is there a better built-in way to delete nodes?
    – Greg
    Mar 9, 2011 at 17:56
  • 3
    There is node_delete() and node_delete_multiple(), see tim.plunket's answer, but that isn't designed to handle thousands of nodes, see api.drupal.org/api/drupal/modules--node--node.module/function/…. It loads all nodes and then iterates over them in a single request. So pretty much have to use a contrib module like bulkdelete if you want to delete hundreds or thousands of nodes.
    – Berdir
    Mar 9, 2011 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.