How to delete all node programatically in Drupal 8

You can use the following snippet from devel PHP or your custom module to delete all the nodes programmatically.

$query = \Drupal::entityQuery('node');
$result = $query->execute();
$controller = \Drupal::entityManager()->getStorage('node');
$entities = $controller->loadMultiple($result);
$controller->delete($entities);

 

Tags