0

I have a view where I need to include an OR group for example (a + b) OR (C) as well as using Exposed Filters that will apply to both groups, giving something like (Ex1 + Ex2 + ((a + b) or c))). Is there any way I can make the exposed filters apply to both groups at the same time?

I thought it may be possible using nested or sub groups but I know it is not possible to create nested or sub groups in filters through the UI.

1 Answer 1

0

I think you can achieve it by adding new filter group from views UI.

enter image description here

Edit: If your case is more special then you can achieve it using hook_views_query_alter.

if (!$new_feed) { 
  $query->where[0]['conditions'][1]['field'] = 'node.nid'; 
  $query->where[0]['conditions'][1]['value'] = array(); 
  $query->where[0]['conditions'][1]['operator'] = 'IN (' 3, 4 5')'; 
} 
else { 
  $query->where[2]['conditions'][1]['field'] = 'node.nid'; 
  $query->where[2]['conditions'][1]['value'] = array(); 
  $query->where[2]['conditions'][1]['operator'] = 'IN (1, 2, 3); 
}

You can unset where condition as per your use case.

5
  • thanks for your answer Yogesh, but as well as using the or group I need to use exposed filters which would apply to both filter groups, and this is the part I am having difficulty with. Perhaps I did not make it clear enough in my question but what I actually need is something like (Ex1 & Ex2 & ((A & B) or C)))
    – Ben
    Apr 26, 2018 at 7:22
  • In this case you can also alter your views queries in and inside alter function you can create condition like you want. hook_views_query_alter Apr 26, 2018 at 7:41
  • Thank you for that. Would you have an example at all I could look at?
    – Ben
    Apr 26, 2018 at 11:38
  • Implement the hook and look into $query object. There you can find operator table column name and value. if (!$new_feed) { $query->where[0]['conditions'][1]['field'] = 'node.nid'; $query->where[0]['conditions'][1]['value'] = array(); $query->where[0]['conditions'][1]['operator'] = 'IN (' 3, 4 5')'; } else { $query->where[2]['conditions'][1]['field'] = 'node.nid'; $query->where[2]['conditions'][1]['value'] = array(); $query->where[2]['conditions'][1]['operator'] = 'IN (1, 2, 3); } You can also unset where condition Apr 27, 2018 at 11:00
  • Thank you very much. Perhpas if you can edit your answer to say that it can be done using hook_views_query_alter, I can then mark it as correct. Thanks again.
    – Ben
    Apr 27, 2018 at 14:26

Your Answer

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

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