Drupal - entityQuery with multiple conditions on taxonomy terms returns no result

The reason you can't do that is that both of these fields are entity reference to the same entity. That means that the base table is the same base table.

You are asking Drupal to Join the taxonomy_data table to the node table and then make an impossible AND condition on it.

P.S.

You can use condition('field_tags', 1); instead of condition('field_tags', [1], 'IN');

And as mentioned in the comments, the AND condition group is the default, so you don't need to specify it.

P.P.S.

You should have both conditions use the referenced id to be consistent.


A wild, untested guess:

$query = \Drupal::entityQuery('node')
  ->condition('status', 1)
  ->condition('type', 'news');

$query = $query->condition($query->andConditionGroup()->condition('field_tag.entity.name', ['cars'], 'IN'))
  ->condition($query->andConditionGroup()->condition('field_category.entity.name', ['sport'], 'IN'));

If this doesn't work then find me in IRC #drupal-contribute next week and we will get to the end of it.

Tags:

Entities

8