Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Search By Category in WordPress (Best Method)

When setting up a new WordPress blog, one feature we always prioritize is a search bar. Specifically, a search by category bar. 

A category-specific search helps readers find exactly what they’re looking for, keeps them engaged longer, and encourages better content organization. For blogs or online stores, it can even boost conversion rates by guiding users to relevant offerings more quickly.

While adding this feature might seem daunting, it’s actually quite simple with the right tools. In this guide, we’ll walk you through adding a search by category function to your WordPress blog using SearchWP.

How to search by category in WordPress (2 ways)

Why Add Search By Category to WordPress?

Categories are an easy way to organize the content on your WordPress website. Categories can also help visitors find interesting posts.

For example, many sites show their categories in a dropdown menu or sidebar.

A list of post categories on the WPBeginner website

If you have lots of blog posts, then you can go one step further and add a search by category feature to your website. This can help visitors find the content they’re looking for, even if you have lots of blog posts.

If you are using WooCommerce, then you can even create a product category search for your online store and get more sales.

Product categories on an eCommerce site

Similarly, if you run a WordPress membership site, then you might use search by category to help visitors find specific members, groups, forums, online courses, and more.

With that being said, let’s see how you can add a search by category feature to WordPress. You can use the quick links below to navigate through this tutorial:

Step 1: Install and Set Up SearchWP

The easiest way to add a category-specific search to WordPress is by using SearchWP. It is the best search plugin and allows you to improve the built-in WordPress search.

With SearchWP, you can search content that WordPress ignores by default, including custom post types, PDF files, WooCommerce products, and categories.

To learn more, see our detailed SearchWP review.

First, you need to install and activate the SearchWP plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, go to SearchWP » Settings and then click on the ‘General’ tab.

Activating the SearchWP WordPress plugin

Here, you need to enter your license in the ‘License Key’ box. You can find this information under your account on the SearchWP site. Once you are done, make sure to click the ‘Verify Key’ button.

Step 2: Customize Your WordPress Search Algorithm

After activating the plugin, you can fine-tune how SearchWP indexes, searches, and displays your content. You can think of this as creating a custom Google search algorithm that’s just for your WordPress blog or website.

To get started, head over to SearchWP » Algorithm.

Creating a search by category feature for WordPress

Here, you’ll see a section for the different content types that SearchWP searches by default, such as pages, posts, and media files.

Each section has its own Application Attribute Relevance sliders, which allow you to control how SearchWP ranks the content on your website.

For example, if you move the ‘Title’ slider to the left and the ‘Content’ slider to the right, then the content will carry more weight than the title.

Changing the attribute relevancy settings in WordPress

You can even exclude specific pages, authors, and more from WordPress search.

Another option is to include more content in the search results by clicking on the ‘Sources & Settings’ button.

Configuring your website's search algorithm using SearchWP

You can now check the box next to the different content types. For example, you may want to make blog comments searchable or add PDF indexing and searching in WordPress.

When you are happy with your changes, click on the ‘Done’ button.

Making comments, PDFs, media, and more searchable on a WordPress website

This adds a new section for each new content type. You can now change the attribute relevance using the different sliders.

Once you are happy with how the search is set up, scroll to the top of the screen and click the ‘Save’ button.

Saving your SearchWP search engine settings

SearchWP will now rebuild the index automatically. Depending on the speed of your Internet connection and your WordPress hosting provider, this may take a few minutes.

As soon as you see ‘Index Status 100%,’ you’ll know that SearchWP has indexed all your content and settings.

Rebuilding the search index on your WordPress website

Step 3: Create a Search by Category Form

At this stage, you’re ready to create a search by category form. This will allow visitors to choose the category they want to search. If you want detailed instructions, you can read our article on how to create a custom search form in WordPress.

First, go to SearchWP » Search Forms. Then, click ‘Add New.’

Adding a custom search form to your WordPress website

Next, give your new search form a name so that you can identify it later. This will come in handy if you decide to create multiple search forms for one website.

Then, choose a layout theme for the search form. Since we’re creating a category-based search form, you should choose ‘Category Search.’

Creating a search by category form with SearchWP

Scrolling down, you will see that the ‘Category Search’ option has been enabled. You can also activate Quick Search (which will give search term recommendations) and Advanced Search (which lets users search using advanced filters).

As for the Engine, you can just select ‘Default’ as that’s what we edited earlier in Step 2.

For the Results Page, you can choose the default WordPress search results page or create a new one using SearchWP. If you’re interested in the second option, then read our guide on how to customize the search results page in WordPress.

Configuring the search form settings in SearchWP

Next, on ‘Type of Search,’ you can select what types of content can users find when using the search engine. If you want this search by category form to only show blog post results, then you can add ‘Posts.’

But if you want to include pages and media files, then go ahead and enter ‘Pages’ and ‘Media.’

In the ‘Select Category’ field, you can include or exclude any blog post categories in the dropdown menu of the search form.

Below that, you can change the placeholder text in the field label and enable or disable the Search Button if needed.

Customizing the search by category form settings in SearchWP

Toward the bottom, you can modify the search form’s border, border color, and font, as well as the button’s shape, label, background color, and font.

Feel free to make the design more suitable for your WordPress theme.

Customizing the SearchWP form's style

Once you’re happy with the search form settings, go ahead and scroll up the page.

Then, click ‘Save.’

Saving the SearchWP form

Step 4: Embed the Search by Category Form in WordPress

Now that you have created a search by category form, let’s embed it on your WordPress website. SearchWP offers an easy-to-use search form block that you can add using the Gutenberg editor, Full Site Editor, and the block-based widget editor.

Let’s try adding the form to a WordPress page. Open the block editor for a new or existing page, and click the ‘+ Add Block’ button.

Then, select the ‘Search Form’ block (not to be confused with the ‘Search’ block, which belongs to WordPress and not SearchWP).

Adding the SearchWP search form block in WordPress

Now, in the ‘Block’ tab in the sidebar, select the form you created in the dropdown menu. You will then see your new search by category form displayed.

Feel free to add more elements to the page, like short instructions or images. Then, click the ‘Publish’ or ‘Update’ button.

Selecting a SearchWP form in the block editor

Now, just preview your WordPress page and see what the form looks like on the front end.

Here is what our search by category form looks like:

Example of a search by category form made with SearchWP

To learn more about creating a custom WordPress search engine, check out these guides:

We hope this article helped you add search by category in WordPress. You may also want to see our beginner’s guide on WordPress categories vs tags for SEO and our article on how to create custom taxonomies in WordPress.

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. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

23 CommentsLeave a Reply

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Diiamo

    Thank you, does it support woocommerce product catalog?

    • WPBeginner Support

      The SearchWP plugin does integrate with WooCommerce and would allow you to search for products :)

      Admin

  3. Mrteesurez

    Can this guide be followed to create a search for a support site where each category will includes all support posts for a particular services or branch and other for theirs ??
    Thanks for this post.

    • WPBeginner Support

      If we understand correctly then yes, you should be able to do that :)

      Admin

  4. Hansan

    Hey help , I want to create a search box for web page and it should search in only one page category. How can i do that in wordpress.

  5. Eric Thomas

    This is exactly what I was looking for! Needed a sidebar for a separate review section, with a search bar that only searched that separate section. So this was perfect

  6. philips

    Thanks for the support for this awesome plugin. i have tried the plugin, the search by name works fine but the category search is not showing any result. i guess it is not compatible with 3.5 — >3.8.
    i have tried changing “cat” to “category” but all to no avail . Any quick help will be hugely appreciated. Thanks in advance.

  7. Eric

    After I installed this plugin, the original categories widget doesn’t work any more!
    Once I removed the plugin, it’s work again!
    I still can’t find the reason.

    Could someone tell me how to fix the problem?

    Thanks a lot!

  8. sergio

    i run both regular search with google custom search, and the search category plugin, . i modified the searchform.php in order to have google search results ( with this shortcode ).
    When i use the search by category plugin the results are the same of the standard so they are not filtered obviously because i use in both case google custom search .
    so i would reset thestandard only for () for this plugin
    how can i Do?
    thanks

    • WPBeginner Support

      you can not use search by category and Google custom search. You can create two different forms and search templates.

      Admin

  9. Srinivas

    Team,

    I tried the steps above, but when i added [sbc] in the text area, it just displayed that as a text instead of calling the search box. Am i missing something here.

    Else, also not sure where i can add the mentioned code in the theme template. Could someone help me with the specific theme file i need to edit.

    Thanks

  10. Gretchen Louise

    Oh I’m so glad to find this plugin! I think I need to keep looking though because I need to have it search specific pages on my site as well as some categories of posts.

  11. mike

    Really saved my time a lot ………..

    This plugin still works with wordpress 3.5.1 !!!!

    • Alan

      Can this be used for search results?

  12. Gitte Hansen

    Search by category is only tested for WordPress version up to 3.4.2 – is it ok to install anyway? I use 3.5.0
    I really look forward to a functionality which will make it easier for my readers to browse and seach in my categories.
    Greetings Gitte

  13. Corrinda

    I just did a review of different options for a client site and eventually installed the Search Everything plugin. It gives you the option to also configure what gets searched. And in this case I wanted to exclude a couple of categories.

  14. Azim

    If no serious customization is needed, you could just use the following snippet in your searchform.php

    <form method="get" id="searchform" action="<?php echo home_url(); ?>">
    <input type="search" id="s" name="s" />
    <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?>
    </form>

    • Pam

      What would this do for you? tried it but nothing.

  15. Alan

    I use Relevanssi on one of my sites and it is great but I would love to add something like this to narrow search fields but rather than narrow by category. I’d like to narrow by custom taxonomy.

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.