11 November 2022

You can iterate through entities using entitiyQuery. In this simple snippet you can see that the only condition is type. So using this exact one you can iterate through entities in a certain node type.

Source code viewer
  1. $query = \Drupal::entityQuery('node')
  2. ->condition('type', 'my_node_bundle');
  3. $results = $query->execute();
  4.  
  5. foreach ($results as $nid) {
  6. dpm($nid);
  7. }
Programming Language: PHP