title: Exclude multiple custom taxonomies terms from Wordpress search
body: <p>I am excluding from Wordpress search results any posts or custom posts with custom taxonomies set to specific terms. I want to be able to add more taxonomies and terms simply (like in an array) without having the duplicate the function, and ensure I'm doing it efficiently. </p>
  
  <p>Can anyone suggest a cleaner function that accommodates this?</p>
  
  <pre><code>/* Exclude from WordPress Search using custom taxonomy */
  add_action( 'pre_get_posts', function ( $query ) {
      if ( is_admin() || ! $query-&gt;is_main_query() ) {
          return;
      }
  
      // Exclude Terms by ID from Search and Archive Listings
      if ( is_search() || is_tax( 'marque' ) ) {    
          $tax_query = array([
              'taxonomy' =&gt; 'site_search',
              'field' =&gt; 'term_id',
              'terms' =&gt; [ exclude_page ],
              'operator' =&gt; 'NOT IN',
          ]);
  
          $query-&gt;set( 'tax_query', $tax_query );
      }
  }, 11, 1 );
  
  
  /* Exclude from WordPress Search using custom taxonomy */
  add_action( 'pre_get_posts', function ( $query ) {
      if ( is_admin() || ! $query-&gt;is_main_query() ) {
          return;
      }
  
      // Exclude Terms by ID from Search and Archive Listings
      if ( is_search() || is_tax( 'marque' ) ) {    
          $tax_query = array([
              'taxonomy' =&gt; 'job_status',
              'field' =&gt; 'term_id',
              'terms' =&gt; [ closed ],
              'operator' =&gt; 'NOT IN',
          ]);
  
          $query-&gt;set( 'tax_query', $tax_query );
      }
  }, 11, 1 );
  </code></pre>