views query alter not working when view appears in sidebar I have a block view, and I want to change my query, to add contextual filter. I made a views query alter but when the view appears in sidebar as block view this function doesn't work.

function bpm_views_query_alter(&amp;$view, &amp;$query) {
   if ($view-&gt;name == 'single_job' &amp;&amp; $view-&gt;display_handler-&gt;display-&gt;id =='block_1' ){
      $nid = _get_job_nid_from_url();
      $query-&gt;where[1]['conditions'][2]['value'] = $nid;
   }
}


If I add the same block view in page content then views query alter work as expected. The page is created by page callback and this is following code how i add block view in page content

$output = views_embed_view('single_job', $display_id = 'block_1', $category);
I think you problem is there that $nid not passed correctly,edit your views, instead of your filter, set filter by contextual filter then in your page passed it by contextual filter parameter with 

$view= views_embed_view('single_job', $display_id = 'block_1', $category);
$view-&gt;set_arguments(array($node-&gt;nid));
$output = $view-&gt;preview();
print $output;


not longer  need query alter function

/*
function bpm_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'single_job' &amp;&amp; $view-&gt;display_handler-&gt;display-&gt;id =='block_1' ){
    $nid = _get_job_nid_from_url();
  $query-&gt;where[1]['conditions'][2]['value'] = $nid; 
 }
}*/