I am using the following code to sort the published nodes basing on the value stored from the Statistics module.
$query = Drupal::entityQuery('node') ->condition('status', 1) ->range(0, 5) ->sort('totalcount', 'DESC' ); $result = $query->execute();
The code is causing the following exception.
DrupalCoreEntityQueryQueryException: ‘totalcount’ not found in DrupalCoreEntityQuerySqlTables->ensureEntityTable() (line 316 of core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).
How do I sort nodes basing on the totalcount value stored from the Statistics module?