Modifying Views
Posted on: Thursday, June 25th 2009 by Steve Shen
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.

Comments
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! :-)
Thanks we just did that.
It is really very interesting article as well very informative, thanks.
thanks its very full to me
Is it just me, or is the black background extremely hard to read on?
I'm with Sue Ellen here, either I've been at the PC to long & my eyes are tired, or a lighter blog background would be easier to read
I like the color scheme , the text is very easy to read and very easy on the eye .
I much prefer this than a ligh text on a light background that really hurts my eyes .
Post new comment