Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Exclude Specific Pages, Authors, and More from WordPress Search

Do you want to exclude specific pages, posts, authors, and more from WordPress search?

By default, WordPress search includes all posts and pages in the search results. However, you may want to exclude some content, such as your store’s checkout page, premium online courses, or subscriber-only content.

In this article, we’ll show you how to easily exclude specific pages, posts, authors, categories, and more from the WordPress search results.

How to exclude specific pages, authors, and more from WordPress search

Why Exclude Items from WordPress Search?

The default WordPress search shows results from all WordPress posts and pages, which works for most sites.

However, if you’re running an online store, then you may not want to include all pages in the search results. For example, you’d likely want to exclude the checkout, cart page, and thank you page from search.

Similarly, if you’re running a WordPress membership website or selling online courses, then you’ll want to exclude your premium, members-only content from public search results.

Some WordPress website owners may want to hide category or tag archive pages, while others may want to hide posts written by specific authors. By excluding items from the search results you can offer a better user experience and help visitors find what they’re looking for.

That being said, let’s take a look at how to easily exclude items from WordPress search.

Note: In this guide we’ll show you how to exclude content from your website’s search results. However, this content will still show up in the search engines. If you want to stop search engines from indexing a page, then check out our guide on how to hide a WordPress page from Google.

Install and Setup the SearchWP WordPress Plugin

The easiest way to exclude pages, authors, categories, taxonomies, tags, and more is by using the SearchWP plugin. It’s the best WordPress search plugin used by over 30,000 sites.


It’s very beginner friendly and lets you improve WordPress search to provide more helpful and relevant results.

You can use this plugin to exclude entire content types from the search results, such as all your pages. You can also use it to exclude specific pages, posts, and custom post types.

The first thing you need to do is install and activate the plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, head over to Settings » SearchWP and then click on ‘License.’

Enter SearchWP license

Then, you need to enter your license key into the ‘License’ box and click the ‘Activate’ button. You’ll find this information in your SearchWP account.

Next, it’s time to configure your initial search engine settings. This is similar to creating a Google search algorithm that’s only for your WordPress blog.

To get started, click on the ‘Engines’ tab.

SearchWP default engine

You need to create a sitewide search engine before you can start excluding pages, posts, authors, and more from your custom search results page.

On this screen you’ll see a section for each content type that SearchWP includes in its results by default.

Every section has its own Applicable Attribute Relevance sliders that control how SearchWP will rank your site’s content.

For example, if you want a post’s content to carry less relevancy than its title, slug, or excerpt, then you need to drag the ‘Content’ slider to the left.

SearchWP algorithm sliders

At this point, you can exclude entire content types from the search results, such as all pages, posts, and custom post types.

For example, most WordPress blogs have a few pages such as a contact form or homepage. You may want to exclude all pages from search so only blogs show up in the search results.

To do this, simply click the ‘Sources & Settings’ button.

Click sources and settings

This opens a popup where you can uncheck the content that you want to exclude from WordPress search.

Once you’ve done that, click on the ‘Done’ button.

Exclude all pages, posts, or custom post types

When you’re happy with how the search engine is setup, go ahead and click the ‘Save Engines’ button to create your first search engine.

Now, the excluded content will never show up in the search results.

Save search engine

Exclude Specific Posts, Pages, and Custom Post Types from WordPress Search

Once you’ve created an initial search engine, you can exclude specific posts, pages, and custom post types from the WordPress search results.

For example, if you’re using WooCommerce then you might exclude the site’s contact form, account login, and checkout pages so the search bar only ever returns products. In this way, you can create a smarter WooCommerce product search and get more sales.

To do this you’ll need to install Exclude UI by going to SearchWP » Extensions.

Here, find the Exclude UI extension and click on its ‘Install’ button.

Installing the Exclude UI extension

Next, open up the post, page, or custom post type that you want to exclude from the WordPress search results.

If you’re excluding a single post, then make sure the ‘Post’ option is selected in the right hand menu, then check the ‘Exclude from search’ box.

Exclude single post from search

Make sure to click ‘Update’ to save your changes.

You can also exclude specific pages and custom post types following the same process described above. The only difference is the right hand menu will say ‘Page’, or the name of the custom post type, instead of ‘Post.’

Exclude Specific Categories, Tags, and Custom Taxonomies From WordPress Search

You can also exclude specific categories, tags, and other custom taxonomies from the WordPress search results.

For example there might be some tags that authors use to organize and manage content in your multi-author WordPress blog. Since these tags are just for your team’s reference, you’ll want to exclude them from the search results.

To do this, simply go to Settings » SearchWP and then click the ‘Edit Rules’ button in the ‘Posts’ section.

Click edit rules

This opens a popup where you can edit the search engine rules.

Simply click the ‘Add Rule’ button to create your first rule.

Click add rule button

To exclude a specific category, select ‘Exclude entries if:’ in the first dropdown, and then type your category name into the empty box. You can also type in custom taxonomies to exclude them as well.

Then, click the ‘Done’ button.

Exclude specific category

To exclude specific post tags from the search results, simply open the first dropdown menu and select ‘Tags.’

Then, type the name of your tag in the empty box, and click ‘Done’.

Exclude specific tags

To add another rule, simply click the ‘Add Rule’ button again.

Once you’re finished customizing your rules, make sure you click the ‘Save Engines’ button to update your search engine.

Now, when visitors search your WordPress website, SearchWP will exclude all the selected categories, tags, or custom taxonomies from its results.

Exclude Specific Author Posts From WordPress Search

If you’ve added multiple authors to your WordPress blog, then you may want to exclude specific authors from the search results. For example, you might exclude an author’s blogs if they’re no longer writing for your website, or if they only have a few posts.

You can exclude all the posts created by a specific author by adding code to your website. If you haven’t done this before, then see our beginner’s guide to pasting snippets from the web into WordPress.

Often you’ll find code snippets in WordPress tutorials with instructions to add them into your theme’s functions.php file.

The biggest problem is that even a tiny mistake in the custom code snippet can cause common WordPress errors or even break your website completely.

Luckily, there is an easier way for users to add and manage custom code snippets.

WPCode is the most popular code snippets plugin used by over 1 million websites. It makes it easy to add code snippets without having to edit functions.php.

The first thing you need to do is install and activate WPCode. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, click on ‘Code Snippets’ in the admin bar and then select ‘Add New.’

The WPCode code snippets plugin for WordPress

This will bring you to the ‘Add Snippet’ page. Here you can choose a code snippet from the pre-made library or add custom code to your WordPress theme.

Since we want to add custom code, hover over ‘Add Your Custom Code (New Snippet)’ and then click on the ‘Use snippet’ button when it appears.

Adding custom code to WordPress

In the ‘Add title for snippet’ field, type in a name for the snippet.

This is just for your reference so you can use anything you want.

Adding a title to a custom WordPress code snippet

Next, open the ‘Code Type’ dropdown and select ‘PHP,’ since we’re adding a custom PHP code snippet.

After that, you can go ahead and paste the following snippet into the code box:

function wpb_search_filter( $query ) {
  if ( $query->is_search && !is_admin() )
    $query->set( 'author','-24' );
  return $query;
add_filter( 'pre_get_posts', 'wpb_search_filter' ); ?>

You’ll need to replace ’24’ with the user ID of the author you want to exclude. If you need help finding the user ID, then see our guide on how to find IDs in WordPress.

You can also exclude multiple authors from the search results by adding their user IDs separated by a comma.

function wpb_search_filter( $query ) {
  if ( $query->is_search && !is_admin() )
    $query->set( 'author','-24, -12, -19' );
  return $query;
add_filter( 'pre_get_posts', 'wpb_search_filter' ); ?>

Below the code box, you will see insertion options. There are two main insertion options: Auto Insert and Shortcode.

You’ll want to choose the ‘Auto Insert’ method, so that WPCode automatically inserts and executes the code across your entire site.

Auto inserting a custom WordPress code snippet

You can also assign tags to your code snippet. This can help sort your code snippets by topic and functionality.

When you’re happy with how the snippet is set up, scroll to the top of the screen and click on ‘Save Snippet.’

Saving a WPCode WordPress code snippet

Finally, you can make the code snippet live on your site by clicking the ‘Active’ toggle.

Don’t forget to save this change by clicking on ‘Update.’

Activating a custom code snippet in WordPress

Now, the author will be excluded from the WordPress search results.

We hope this article helped you learn how to exclude specific pages, custom post types, authors, and more from WordPress search. You may also want to see our guide on how to track website visitors to your WordPress site and our expert picks of the best virtual business phone number apps.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

16 CommentsLeave a Reply

  1. Hi!

    I have a doubt, it’s possible to exclude a word from search?

    For example:
    – Keyword to search: laptop
    – Not search with the word: macbook

    The results should be all the laptops but no the ones who contains the word “macbook”

    Thanks and regards!

    • That kind of customization would require editing how your search engine works, it would be better to use tags or categories for separating your content like that normally.


  2. Hi,

    Will this affect SEO in any way?

    I want a specific post to be excluded from my own sites Searchbar, but still want it to be found by Google SERP’s.


    • It will make your page more difficult to find and we have not tested but it shouldn’t have a major effect as long as the page can be easily found.


  3. Hi,
    The code in “Exclude Specific Tags from WordPress Search” section is faulty and causes WP to throw an error.

      • Please look at the snippet once again. (I am only talking about the part after the heading which says “Exclude Specific Tags from WordPress Search”) First of all the syntax is wrong. on line 4 you have } but you have never started a block with {.
        Second, You have :
        add_filter( ‘pre_get_posts’, ‘wpb_search_filter’ );
        but never defined a function named : wpb_search_filter

        basically the code is missing one line at the type which should be :

        function wpb_search_filter( $query ) {

        So either it’s expected from the users to complete the code from what you added in the upper parts of this article or this snippet of code is not complete.

        • Thank you for clarifying that, it looks like our code block had a hiccup and we resolved the issue so the code should show correctly now. :)

  4. Hi there!

    By checking this “search exclude” will the post still be indexed and accessible via google?

    I’m trying to find the best way to have a post type available to those who have a link to it. However I do not want people to be able to access it via google or have to password protect the posts. Any suggestions for the best way to do that? (I can explain further if needed)

    Any help appreciated! Thanks :)

  5. Thank you so much for this post! I was having trouble not just with getting Google to stop indexing my Thank You page, but also preventing my own site from indexing it in the search as well! This solved both of my problems.

  6. I have installed the plugin, checked the exclude check on one page but I continue to see on search result, why?

    • There are a few possible reasons. If you reach out to the plugin’s support they should be able to help you solve the issue :)


  7. Thanks for the VERY helpful post. As I am not a “coder,” I do have one question…

    How do I exclude **more than one** specific terms in a custom taxonomy? How will the code change?

  8. Once I’ve excluded a certain page from a WP Search, do I have to change the setting from ‘Public’ to ‘Private’?
    I want to be able to give only certain people access to a certain page (for free information or paid information)- but they’re not editors on my blog.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.