Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #608388

    Hi there!

    Is is possible to exclude posts from a specific category from showing up as search results?

    Thanks!

    #608556

    Hey worldfuturecouncil!

    Please add the following to your functions.php file

    function wcs_exclude_category_search( $query ) {
      if ( is_admin() || ! $query->is_main_query() )
        return;
    
      if ( $query->is_search ) {
        $query->set( 'cat', '-22, -21' );
      }
    
    }
    add_action( 'pre_get_posts', 'wcs_exclude_category_search', 1 );

    where you replace -22, -21 with the category IDs u need

    Cheers!
    Basilis

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.