How can I add multiple conditions for the same field taxonomy term in views query? I make some query for views filter for nodes. Use in hook_views_query_alter.

$definition = [
   'table' =&gt; 'node__field_characs',
   'field' =&gt; 'field_characs_target_id',
   'left_table' =&gt; 'taxonomy_index',
   'left_field' =&gt; 'tid',
   'operator' =&gt; '='
];
$join = \Drupal::service('plugin.manager.views.join')-&gt;createInstance('standard', $definition);
$rel = $query-&gt;addRelationship('node__field_characs', $join, 'taxonomy_index');
$query-&gt;addTable('node__field_characs', $rel, $join, 'node__field_characs');


I add array of conditions.

$q_and = db_and();
foreach($ch_id as $key =&gt; $val_array){
   $q_and-&gt;condition('node__field_characs.field_characs_target_id', $val_array, 'IN');
}
$query-&gt;addWhere(0, $q_and);


But if array $ch_id have more then 1 elements, it works wrong. It does not show any nodes.

A similar problem is described here Perform a query with an entity field condition with multiple values. But how can this be applied in this case?
you try this code:

$and = $query-&gt;andConditionGroup();
foreach($ch_id as $key =&gt; $val_array){
   $and-&gt;condition('node__field_characs.field_characs_target_id', $val_array, 'IN');
}

$query-&gt;condition($and);