entityQuery filter by content moderation state I need to filter a node by moderation state. I am using the Drupal 8 content moderation module.

I basically want to get NIDs of all nodes in draft state. Something similar to this.

$nids = \Drupal::entityQuery('node')
      -&gt;condition('moderation_state', 'draft')
      -&gt;execute();
You try the code :

$query = \Drupal::database()-&gt;select('content_moderation_state_field_data', 'ms');
    $query-&gt;join('node_field_revision', 'nf', 'nf.nid=ms.content_entity_id AND nf.vid=ms.content_entity_revision_id AND nf.langcode=ms.langcode');
    $query-&gt;fields('ms');
    $query-&gt;condition('ms.moderation_state','draft');
    $results = $query-&gt;execute()-&gt;fetchAllAssoc('content_entity_id');


Because entityQuery not filter content moderation