I'm running an app where I am searching for every nodes of a given content type.
$nids = \Drupal::entityTypeManager() ->getListBuilder('node') ->getStorage() ->loadByProperties([ 'type' => 'courses', 'status' => 1, ]);
I'm searching for a way to sort the results among a custom field of my nodes.
EDIT: I do not understand what's going on. Thanks to @4k4, I wrote this query:
$query = \Drupal::entityTypeManager() ->getListBuilder('node') ->getStorage() ->getQuery(); $query->condition('type', 'post'); $query->condition('status', 1); $query->condition('field_category', $k); $query->sort('field_ordering', 'ASC'); $nids = $query->execute(); $nids = Node::loadMultiple($nids);
$r prints nothing. Same for
$r. But $results contains my results. What's going on ?
The sorting doesn't work by the way.