You can't reuse the same query object for these two different things. ->pager()
permanently turns the query into a paged query, and ->count()
permanently turns it into a count query. Trying to do both results in unpredicted behavior depending on execution order.
The code you pasted actually does return the total count, because count trumps pager if both are set when the query is first executed. But afterwards it's a count query and will always return a number:
// With 50 nodes in the database:
$query = \Drupal::entityQuery('node');
$query->condition('status', 1);
$query->condition('type', 'news');
$query->pager(9);
$count = $query->count()->execute();
// $count is 50, the ->pager() is ignored.
$items = $query->execute();
// $items is 50, not an array. It's permanently a count query now.
Flipping the execution order:
$query = \Drupal::entityQuery('node');
$query->condition('status', 1);
$query->condition('type', 'news');
$query->pager(9);
$items = $query->execute();
// $items is an array with 9 nodes.
$count = $query->count()->execute();
// $count is 9.
Instead, you need to use two separate queries here:
$count = \Drupal::entityQuery('node');
->condition('status', 1);
->condition('type', 'news');
->count()
->execute();
$items = \Drupal::entityQuery('node');
->condition('status', 1);
->condition('type', 'news');
->pager(9)
->execute();