title: Difference between add_filter versus add_action
body: <p>I was looking over my functions.php and wondering why CODE A uses <code>add_action</code> while CODE B uses <code>add_filter</code> ?<br>
  The main goal of CODE A is to <strong>both include and exclude</strong> specific categories.<br>
  The main goal of CODE B is to <strong>exclude</strong> specific categories.  </p>
  
  <p>Is it correct to use <code>add_action</code> for CODE A<br>
  and <code>add_filter</code> for CODE B? </p>
  
  <p><br />
  <br /> 
  <strong>CODE A: Display specific category (called "featured") for homepage, instead of "the most recent posts"</strong>  </p>
  
  <pre><code>function featured_category( $query ) {
  
      if ( $query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query() ) {
          $query-&gt;set( 'category_name', 'featured' );
          $query-&gt;set( 'category__not_in', array(60, 61) );
          $query-&gt;set( 'posts_per_page', 5 );
      }
  }
  add_action( 'pre_get_posts', 'featured_category' );
  </code></pre>
  
  <p><br />
  <br /> 
  <strong>CODE B: Exclude "sponsored posts categories" for search results</strong>  </p>
  
  <pre><code>function search_filter($query) {
  
      if ( $query-&gt;is_search &amp;&amp; $query-&gt;is_main_query() ) {
          $query-&gt;set('post_type', 'post');
          $query-&gt;set( 'category__not_in', array(60, 61) );
          $query-&gt;set( 'posts_per_page', 20 );
      }
  
      return $query;
  }
  add_filter('pre_get_posts', 'search_filter');
  </code></pre>