Referring a particular display in Drupal's Hook Views Query Alter

Submitted by ionut on 30/08/2011

The documentation of this function does not tell us how to alter a particular display, probably they thought we'll figure it by ourselves... anyway... in the $view object we have a member named current_display which is actually a string representing as you guessed the current display.

Now when you want to alter only one display you can  write something like this:

function [your_module_name]_views_query_alter(&$view, &$query) {
        if (($view->name == '[view_name]') && ($view->current_display == '[display_name]')) {

                 //do something

        };
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.