Oct 26, 2020 in Drupal 8, Snippets

A simple query example for drupal 8 and 9.

use \Drupal\node\Entity\Node; 

// EntityQuery articles
  $nids = \Drupal::entityQuery('node')
    ->condition('status', 1)
    ->condition('type', 'article')
    ->sort('created', 'DESC');
    ->execute();

  $nodes = Node::loadMultiple($nids); 
   // Loop over your node objects here
   foreach($nodes as $node) {
     $title = $node->getTitle();
   }

  
 

 

Comments