Modifying Views
Thu, Jun 25, 2009 by Steve
We use the Views UI a lot to create custom pages, blocks, etc. Sometimes it does not give us exactly what we want and we would like to modify the generated sql query. It's possible to achieve this through the 'views_query_alter' hook. For example, we can do something like:
function example_module_views_query_alter(&$view, &$query) {
if($view->name == 'view_to_modify') {
$query->where[0]['clauses'][] = 'node.nid IN (10, 20, 30, 40, 50)';
...
}
}
That modifies the WHERE part of the sql query of the particular view. It helps to print out the 'query' variable before making any modifications to it.
Triyono posted on November 21, 2009 12:51 pm
It is really very interesting article as well very informative, thanks.
admin posted on June 26, 2009 5:22 pm
Thanks we just did that.
Gurpartap Singh posted on June 26, 2009 8:52 am
Please format your teaser properly, to prevent styling problems on Drupal planet. After you do, request some maintainer to refresh your content on planet to let every post there render properly. ;)
Thanks! :-)
Post new comment