I have a content type that has a entity reference field that allows users to add multiple taxonomy terms in that field. I'm attempting to perform queries that grab nodes that have a specific set of taxonomy terms within that field.
Using one value in that field works fine, like so.
$query = \Drupal::entityQuery('node')
->condition('status', NODE_PUBLISHED)
->condition('type', 'custom_type')
->condition('custom_taxonomy', 2)
->sort('field_last_name', DESC);
Where 2 is the id of the term I'm searching for. However when I attempt to search for nodes that contain two specific terms like so,
$query = \Drupal::entityQuery('node')
->condition('status', NODE_PUBLISHED)
->condition('type', 'custom_type')
->condition('custom_taxonomy', [2,8])
->sort('field_last_name', DESC);
I receive the error
Invalid parameter number: number of bound variables does not match number of tokens:
I've also attempted
$query = \Drupal::entityQuery('node')
->condition('status', NODE_PUBLISHED)
->condition('type', 'custom_type')
->condition('custom_taxonomy', [2,8], 'IN')
->sort('field_last_name', DESC);
Which doesn't fail, but doesn't provide the intended results. It displays every node that has either term 2 OR term 8. Instead of term 2 AND term 8 as intended. How would I perform a query that checks if a node has multiple specific values in an entity reference field?