Skip to main content
Category:

Code snippet that can be used to sort nodes by title programmatically drupal 8.

$result=[];
$query = \Drupal::entityQuery('node')
    ->condition('type', 'article')
    ->sort('title', 'DESC');
$nodes_ids = $query->execute();
if ($nodes_ids) {
    foreach ($nodes_ids as $node_id) {
        $node = \Drupal\node\Entity\Node::load($node_id);
        $result[$node->id()] = $node->getTitle();
    }
}

 

 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook