Sort with entityTypeManager I'm running an app where I am searching for every nodes of a given content type.

$nids = \Drupal::entityTypeManager()
  -&gt;getListBuilder('node')
  -&gt;getStorage()
  -&gt;loadByProperties([
    'type' =&gt; 'courses',
    'status' =&gt; 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()
    -&gt;getListBuilder('node')
    -&gt;getStorage()
    -&gt;getQuery();
$query-&gt;condition('type', 'post');
$query-&gt;condition('status', 1);
$query-&gt;condition('field_category', $k);
$query-&gt;sort('field_ordering', 'ASC');

$nids = $query-&gt;execute();
$nids = Node::loadMultiple($nids);


A var_dump on $r[1] prints nothing. Same for $r[2]. But $results contains my results. What's going on ?
The sorting doesn't work by the way.
The change record says if you have entityTypeManager injected, use

$query = $this-&gt;entityTypeManager-&gt;getStorage('node')-&gt;getQuery();


For non-OOP code, $query = \Drupal::entityQuery(); is not deprecated and can still be used.

The linked example for sorting an entity query by using $query:

$query-&gt;condition('type', 'blog_post')
  -&gt;sort('field', 'DESC');
$nids = $query-&gt;execute();