title: Adding add_filter() in Wordpress
body: <p>I am new to Wordpress. I have a search functionality in my website. Now I have to apply some custom sql code/filter in the search query coming through $wp_query. I did some googling and saw that add_filter is good option.</p>
  
  <p>The code which I think I can use is given below  </p>
  
  <pre><code>function apply_custom_filter( $where ) {
  global $wp_query;
  $where = " AND wp_posts.ID IN (SELECt DISTINCT ID FROm TBL_IDS)";
  remove_all_actions ( '__after_loop'); 
  return $where;}
  
  add_filter( 'posts_where' , 'apply_custom_filter' );
  </code></pre>
  
  <p>What confuses me is where to use this. Means in which file I have to place this. In my theme's (I have a theme installed) files I have used it inside header.php but not working :(</p>
  
  <p>Can you please help me in showing my the proper file location  to insert it.</p>
  
  <p>Thanks in Advance.</p>