the following is my views `$query` output.
[where] => Array
(
[0] => Array
(
[clauses] => Array
(
[0] => node.type in ('%s')
[1] => node.status <> 0
[2] => node.promote <> 0
[3] => node.sticky <> 0
)
[args] => Array
(
[0] => test
)
[type] => AND
)
)
[having] => Array
(
)
[group_operator] => AND
(
[0] => Array
(
[clauses] => Array
(
[0] => node.type in ('%s')
[1] => node.status <> 0
[2] => node.promote <> 0
[3] => node.sticky <> 0
)
[args] => Array
(
[0] => test
)
[type] => AND
)
)
[having] => Array
(
)
[group_operator] => AND
I want to override it by using `hook_views_query_alter()`. The default operators are all AND, but i want is
[0] => node.type in ('%s') AND [1] => node.status <> 0 AND [2] => node.promote <> 0 OR [3] => node.sticky <> 0
How do I make the last operator to use OR instead.
the following is my code. but it can't work. what's wrong with it?
function mymodule_views_query_alter(&views,&$query) {
unset($query->where[0]['clauses'][2]);
unset($query->where[0]['clauses'][3]);
unset($query->where[0]['clauses'][2]);
unset($query->where[0]['clauses'][3]);
$query->where[1] = array(
'clauses' => array(
0 => 'node.promote <> 0',
1 => 'node.sticky <> 0',
),
'type' => 'OR',
);
}
unset($query->where[0]['clauses'][2]);
unset($query->where[0]['clauses'][3]);
unset($query->where[0]['clauses'][3]);
those lines can work.
Read »








