Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achraf-jeday/96bd6bd720089b63d78597c890c2d6cb to your computer and use it in GitHub Desktop.
Save achraf-jeday/96bd6bd720089b63d78597c890c2d6cb to your computer and use it in GitHub Desktop.
Delete all content entities in Drupal 8.
<?php
// Delete all nodes.
entity_delete_multiple('node', \Drupal::entityQuery('node')->execute());
// Delete all files.
entity_delete_multiple('file', \Drupal::entityQuery('file')->execute());
// Delete all taxonomy terms.
entity_delete_multiple('taxonomy_term', \Drupal::entityQuery('taxonomy_term')->execute());
// Delete all block content.
entity_delete_multiple('block_content', \Drupal::entityQuery('block_content')->execute());
// Delete all menu links.
entity_delete_multiple('menu_link_content', \Drupal::entityQuery('menu_link_content')->execute());
// Delete all users except 1 and 0.
entity_delete_multiple('user', \Drupal::entityQuery('user')->condition('uid', '1', '!=')->condition('uid', '0', '!=')->execute());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment