Skip to content

Instantly share code, notes, and snippets.

@sarahg sarahg/delete_nodes.php

Last active Aug 29, 2015
Embed
What would you like to do?
Delete all nodes on a Drupal 8 site. We invoke this using "drush scr" while rolling back migrations as a workaround for migrate-rollback not being fully implemented in D8 yet. Could also be useful for awesome April Fool's Day pranks (just kidding, don't do that).
<?php
$query = \Drupal::entityQuery('node');
// Optionally, add the following line to delete only a certain type of node.
//->condition('type', 'event');
$nids = $query->execute();
$storage_handler = \Drupal::entityManager()->getStorage('node');
$entities = $storage_handler->loadMultiple($nids);
$storage_handler->delete($entities);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.