Adding Where clause in Views Query using a custom filter Handler
function query() {
        parent::ensure_my_table(); #$this-&gt;ensure_my_table();
        $alias = $this-&gt;table . '_' . $this-&gt;view-&gt;base_table;
        $operator = ($this-&gt;value['0']) ? 'IS NOT' : 'IS';
    $this-&gt;query-&gt;add_where(0, $alias . '.pid', NULL, $operator . ' NULL');
        #debug($this-&gt;query);   
        parent::query();
    }