How To Exclude Certain Posts, Pages, Categories & Tags From WordPress Search?

WordPress Search includes all the posts, pages, categories & tags in their search results.

Do you wish to exclude certain post, pages, categories or tags from your WordPress search? If yes, then you have come to the right place.

In this article, we will show how you can conveniently exclude specific posts, pages & categories from your WordPress Search Results.

First, let’s understand why it is sometimes needed to exclude certain items from WordPress Search.

Why To Exclude Certain Items From WordPress Search?

The default WordPress Search feature shows the results from all WordPress posts, pages, categories & tags.

This is okay for most of the websites out there & it does not affect the websites’ performance in anyway.

However, if your website is an online store, then there are some pages that you may not want in the search results.

Say for example, the checkout page, my account page, or a thank you page which appears only after successful downloads.

Some websites may not choose to show a specific post, page, category or tag.

Exclude Specific Posts & Pages From WordPress Search

This can be achieved very easily with the help of a WordPress Plugin. Download & install the Search Exclude plugin.

After you have activated the plugin in your WordPress website, edit the post or page that you want to exclude from the WordPress Search Result.

On the edit screen, you will see a Search Exclude box.

Just check the “Exclude from Search Results” CheckBox & click on the Update button to save the changes you have made to your post or page.

By doing this the post or page will not appear in WordPress Search Results anymore.

To view all the items that you have excluded from search, go to Settings -» Search Exclude.

You will see a list of items you have excluded from WordPress Search Results.

You can again include the excluded posts or pages in your WordPress Search Results by unchecking the CheckBox.

How To Exclude Categories & Tags From WordPress Search?

To exclude a specific category or various categories, a specific tag or various tags from your WordPress Search, you will have to add a piece of code to your WordPress website.

How To Exclude Category Or Categories?

Find the Category ID of the Specific Category, that you want to exclude from the WordPress Search Results.

Then add the following code to your functions.php file & don’t forget to replace ‘9’ with the Category ID of the Specific Category that you want to exclude from the search results.

function wp_search_filter($query)
{
 if($query->is_search && !is_admin())
 $query->set('cat','-9');
 return $query;
}
add_filter('pre_get_posts','wp_search_filter');

If you want to exclude many categories simultaneously then, add the following code to your functions.php file & don’t forget to replace ‘9’, ’10’ & ’11’ with the Category IDs of all the Categories, that you want to exclude from the search results.

function wp_search_filter($query)
{
 if($query->is_search && !is_admin())
 $query->set('cat','-9, -10, -11');
 return $query;
}
add_filter('pre_get_posts','wp_search_filter');

In a similar fashion, you can exclude tags as well.

How To Exclude A Tag Or Tags?

If you want to exclude all the posts that come under a Specific Tag, then you can use the code given below in you functions.php file. Just don’t forget to replace ‘3’ with the Specific Tag ID of the Tag that you want to exclude.

function wp_search_filter($query)
{
 if($query->is_search && !is_admin())
 $query->set('tag','-3');
 return $query;
 }
add_filter('pre_get_posts','wp_search_filter');

If you want to exclude the posts that come under Various Tags, then you can use the code given below in you functions.php file. Just don’t forget to replace ‘5’, ‘6’, ‘7’ with the Tag IDs of the Tags, that you want to replace.

function wp_search_filter($query)
{
 if($query->is_search && !is_admin())
 $query->set('tag','-5, -6, -7');
 return $query;
}
add_filter('pre_get_posts','wp_search_filter');

Conclusion

Working with WordPress is really easy & delightful if you know your way around it.

We sincerely hope that this article will help you exclude specific posts, pages, categories & tags from your WordPress Search Results & help you achieve the functionality that you want.

If you liked this article, then please subscribe to Convey Arena for such amazing solution in the field of WordPress.

You can also join our Facebook Group & follow us on Twitter & Instagram. You can also add a comment.

Also See,

A passionate & enthusiastic blogger & part of the Team at Convey Arena, a website, that deals in Affiliate Marketing, Blogging, SEO, Web Hosting and WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top