Need Help using hook_views_query_filter I am using hook_views_query_filter to append my own where clause condition with the where clause of the query generated by the view.

So for this I am using this hook.

Here is my code

   function mymodule_views_query_filter(&amp;$view, $query) {
 if($view-&gt;name = "myview") {
 $query-&gt;where[1] = array(
            'clauses' =&gt; array(
                            '0'=&gt;"field_test_value=0",

                             ),
            'args' =&gt; array('0' =&gt; 'test1', '1' =&gt; 'test2'),
            'type' =&gt; 'OR',
            );
}
print_r($query);
}


So the where clause becomes like this after print_r() funtion.

[where] =&amp;gt; Array
    (
        [0] =&amp;gt; Array
            (
                [clauses] =&amp;gt; Array
                    (
                        [0] =&amp;gt; node.type in ('%s')
                        [1] =&amp;gt; node.status &amp;lt;&amp;gt; 0
                        [2] =&amp;gt; term_data.name = '%s'
                        [3] =&amp;gt; term_data_term_node__term_data.name = '%s'
                    )

                [args] =&amp;gt; Array
                    (
                        [0] =&amp;gt; test1
                        [1] =&amp;gt; test2l
                        [2] =&amp;gt; test3
                    )

                [type] =&amp;gt; AND
            )

        [1] =&amp;gt; Array
            (
                [clauses] =&amp;gt; Array
                    (
                        [0] =&amp;gt; field_test_value=0
                    )

                [args] =&amp;gt; Array
                    (
                        [0] =&amp;gt; test1
                        [1] =&amp;gt; test2
                    )

                [type] =&amp;gt; OR
            )

    )


Where the 0 index of the where clause is coming from the view query and the 1 index of the where is clause is coming from my code.
But it only executes the 1 index of the where clause and display the results only if Where field_test_value=1 and I want something like this.

Where (node.type in ('%s') AND node.status &lt;&gt; 0 AND term_data.name = '%s' AND term_data_term_node__term_data.name = '%s') OR field_test_value=0
You shouldn't alter the query objects properties directly. You need to use the methods it provides. In this case, you need to use add_where(). I think you want to consider something like this:

&lt;?php
$clauses = array("field_test_value='%s'");
$args = array('test1');
$query-&gt;add_where(1, $clauses, $args);
$query-&gt;set_group_operator('OR'); // this is the operator that goes between WHERE groups
?&gt;