I am returning news to my homepage in a carousel. I am using the below query to return the latest 9 articles based on the "created" date. The client however wants to back date some articles (so admin > content > edit node > authored by and change the created date). This however does not seem to work as keeps returning the articles in the actual date order they were created, even if the date was changed manually:
$query = Drupal::entityQuery('node'); $query->accessCheck(FALSE) ->condition('type', 'news') ->condition('langcode', Drupal::languageManager()->getCurrentLanguage()->getId(),"IN") ->sort('created', 'DESC') ->range(0, 9); $nids = $query->execute(); $entities = Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);
What am I doing wrong? It seems to work fine within the actual news page view. The view itself has the sort set as "Content: Authored on (desc)" and this returns the data as expected, but the preprocessor query does not.