I have 2 fields in my contextual filters. Obviously, the default join is AND but I'd like to filter on one or the other field depending on which one of two arguments is provided.

I tried the following approach:

function mymodule_views_query_alter(&$view, &$query){

    if($view->name == 'my_links'){
        switch ($view->current_display) {
            case 'page_2':
                // dsm($query, 'Query');
                $query->where[0]['type'] = 'OR';

                # code...

However, using the devel module to inspect the Views data, the type field in the where section of my View still outputs AND instead of OR.

Which means my attempts to alter my View is not working.

Can anyone help me get this working?


If you have a way of knowing both filter values (like NULL and 12), then I would use hook_views_pre_build and unset the NULL field.

function test_views_pre_build(&$view) {
  // Do some checks for view name and current_display
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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