Drupal 8: delete all nodes of the same type
One should use entity queries instead of acting directly on the database:
$result = \Drupal::entityQuery('node')
->condition('type', 'my_content_type_name')
->execute();
entity_delete_multiple('node', $result);
Setting up ranges like in the other answer shouldn't be too difficult.
See EntityFieldQuery has been rewritten for more information.
you can use the Devel module
- go to Admin->configuration->development->Generate content
( admin/config/development/generate/content ) - select the content type you wish to delete its nodes.
- check "delete all content in these content types.." (important)
- put "0" in "how many nodes would you like to generate" (important)
see attached image for instructions.
attached image
The entity_delete_multiple is deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use the entity storage's delete() method to delete multiple entities:
// query all entities you want for example taxonomy term from tags vocabulary
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', 'tags');
$tids = $query->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage($entity_type);
$entities = $storage_handler->loadMultiple($tids);
$storage_handler->delete($entities);