Drupal 8: delete all nodes of the same type

后端 未结 9 1899
予麋鹿
予麋鹿 2021-02-19 01:34

I have a need to remove all nodes of the same type in Drupal 8 (there are over 7k of nodes).

It wouldn\'t be a problem for Drupal 7 (DB query + node_del

9条回答
  •  -上瘾入骨i
    2021-02-19 02:30

    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.

提交回复
热议问题