I have a view with two filters (A + B). Filter B should only be included in the query, if a specific value in filter A is set (like a "conditional filter").

So I tried to remove the where condition of filter B in hook_views_query_alter by unsetting it:

  foreach ($query->where as $condition_group_key => &$condition_group) {
    foreach ($condition_group['conditions'] as $condition_key => &$condition) {
      if($condition['field'] == 'field_B_to_remove'){

I successfuly removed the where clause but the INNER JOIN on the table of filter B is still part of the query. How can I remove it? I've tried unset($query->tableQueue['node__field_B_to_remove']) but this doesn't work because tableQueue is protected.

Maybe I'm going the wrong way. Basicly I just want to have a "conditional filter".

Some aditional info: The view lists nodes of two different types. You can filter those node types with filter A. The field of filter B only exists in one of the node types. So if you choose filter B you only get nodes of one type. And when you select the other one in filter A you get no result. And that's the issue.

2 Answers 2


you can add field B as a relationship and use as a reference term in your View UI


Leaving this issue as reference for the future: https://www.drupal.org/project/drupal/issues/2830680

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.