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

How to Create Advanced Search Form in WordPress for Custom Post Types

Do you want to create an advanced search form in WordPress for custom posts types?

You can offer your visitors a better website experience by adding a search form that includes your custom post types in the results.

In this article, we’ll show you how to create an advanced search form for custom post types in WordPress, step by step.

How to create advanced search form in WordPress for custom post types

Why Create an Advanced Search Form for Custom Post Types in WordPress?

If you have many different content types, then a custom post type search form lets you help your visitors more easily find the most relevant content.

For example, we use custom post types here at WPBeginner to organize our deals and glossary sections. This keeps them separate from the rest of the content on our site.

If we were to add a custom post types search form to each of these pages, then the search results would only show posts from that category.

This kind of custom search helps your visitors view more pages and stay on your site longer, which gives off positive WordPress SEO signals like lower bounce rate and increased dwell time.

With that said, let’s show you how to create an advanced search form for custom post types in WordPress.

Create a New WordPress Search Algorithm with a WordPress Plugin

The easiest way to create an advanced search form for custom posts types is by using the SearchWP plugin. It’s the best search plugin for WordPress used by over 30,000 sites.

It’s easy to use and and gives you complete control over your WordPress search results.

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, you need to go to Settings » SearchWP and then click on the ‘License’ menu option.

Add SearchWP license key

Then, enter your license key in the ‘License’ box and click the ‘Activate’ button.

You can find this information in your account on the SearchWP website.

Once you’ve done that, you need to click on the ‘Engines’ menu option.

SearchWP engines settings

This brings you to a screen where you can set your search engine settings. Think of it like creating your own Google search algorithm for your website.

With SearchWP, you need to create a site-wide search engine before you can create a custom post types search engine, so we’ll do that first.

You can adjust the search engine settings by clicking on the ‘Posts’, ‘Pages’, ‘Library’, or other custom post type drop downs.

Each section has a ‘Weight Multiplier’ that will change how the search engines rank content.

If you want the search engine to value page titles higher than the content, then adjust the slider accordingly.

Adjust search engine attributes

Once you’re finished customizing your default search engine settings, make sure to click the ‘Save Engines’ button to create your first search engine.

Now that your initial search engine is set up, it’s time to create an advanced search form for your custom post types.

Add an Advanced Search Form Limited to a Single Custom Post Type

To create a custom search box, we’ll start by adding a separate search engine that only targets the custom post types you want.

First, navigate to Settings » SearchWP and then click the ‘Add New’ button.

Add new SearchWP search engine

This will automatically create a new separate search engine.

Next, click the ‘Sources & Settings’ button.

Click sources and settings

This will bring up a popup where you can select the sources for your custom search engine.

Simply uncheck the boxes of the sources you don’t want to include.

In this example, we’ll only leave the ‘Coupons’ box checked, since we want to create a search form that only lets users search through our coupon pages.

You also need to give your search engine a name. Take note of the name in the ‘Engine Name’ box, because you’ll need it at a later step.

Supplemental search engine settings

Then, click the ‘Done’ button.

Once you’ve done that, click the ‘Save Engines’ button to save your new custom post type search engine.

Now, you need to download the SearchWP shortcodes extension to easily add your new custom post search form to WordPress.

First, head over to the SearchWP Shortcodes Extension website and then click the ‘Download available with active license’ button.

Download SearchWP shortcodes extension

After that, you need to install and activate the extension the same way you installed the plugin above.

Now, you can create a new custom post search form page using shortcodes.

Simply navigate to Pages » Add New and then give your page a name.

After that, click the plus ‘Add Block’ icon to bring up the blocks menu.

Add block for shortcodes

Next, type ‘HTML’ into the search box.

Then, select the ‘Custom HTML’ block.

Select custom HTML shortcodes block

Once you’ve done that, you can add the following shortcodes and HTML to your page. If you need more help, then see our guide on how to add a shortcode in WordPress.

[searchwp_search_form engine="coupon" var="searchvar" button_text="Find Results"]
<div class="search-results-wrapper">
 [searchwp_search_results engine="coupon" var="searchvar" posts_per_page=4]
  <h2>[searchwp_search_result_link direct="true"]</h2>
<div class="no-search-results-found">
 No results found, please search again.
<div class="search-results-pagination">
 [searchwp_search_results_pagination direction="prev" link_text="Previous" var="searchvar" engine="my_test_engine"]
 [searchwp_search_results_pagination direction="next" link_text="Next" var="searchvar" engine="my_test_engine"]

The code above will add your search engine, create a section to display the search results, show a no results message if necessary, and add pagination if the results go into multiple pages.

You need to change the engine name engine="coupon" to your own engine name. The rest of the code can stay the same.

Publish SearchWP shortcodes page

Make sure you click ‘Publish’ or ‘Update’ to save your page and make it live.

Your custom post type search engine is now live on your website.

Custom post types search form example

SearchWP is a very flexible and customizable search plugin. You can also use this plugin to add live Ajax search, create a search by category feature, and more.

We hope this article helped you learn how to create advanced search form in WordPress for custom post types. You may also want to see our guide on how to choose the best website builder and our picks of the best live chat software for small businesses.

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

35 CommentsLeave a Reply

  1. Thanks for the information, I want to know whether there is any way I can have dropdown style of search forms, as I have large number of post types, it would make it look ugly if I put all of them below search bar.

  2. Hi, Thanks a lot. This works pretty good for me. I am using dropdown instead of checkbox. But how can I style it to make it smilar to the one in LinkedIn header search section? Does that requires javascript? Do I use font icons for that? I am using fontawesome in my header. But I don’t know how to integrate this with fontawesome in a dropdown.

  3. Sir.. can you plz attach screenshot with tutorials afterwords?? i think it’s more helpful for us..

  4. How could I use this to search a custom table of data. This is for a sports team site, and basically, I need a search box where someone can “Search by”: Last name, First name, or Team.

    So how can I search by a field name?

  5. This is an awesome tutorial, thank you.

    Is there a way that I could mix this with categories? So that I could have both custom post types and categories selectable?

    Thanks again :).

  6. Hi, there isn’t a way to tell the engine to automatically list all terms or tags or custom field? thanks

  7. Nice tutorial… Am designing a custom search for my new site at the moment.

    Curious why you don’t think searching on pages is a good idea?

  8. I’m getting this error after changing the name of the input fields to s[]

    Warning: stripslashes() expects parameter 1 to be string, array given in wp-includes\query.php on line 2179

    I’ve changed the call to stripslashes() call to stripslashes_deep() but it broke other thigs… any sugestions?

  9. I’m looking for a way to have a form with separate controls for location AND category, both in dropdown boxes. Obviously I can do this, but I have no idea how to do a multiple-query search in WordPress. Any ideas?

  10. Do you think is it possible to do the same but including Post Type Categories as well….

    …I mean, the same Post Type checkboxes and when user select an specific checkbox that appear-down other checkboxes but as categories and filter even more the Search of WordPress ?

  11. Awesome! thanks for the help!
    there is one thing though…

    my post types are all styled differently.
    how can I assign the template of a post type with the correct post types?


  12. Great tutorial! One question though: What would the syntax be for making the checkboxes in the form use taxonomies rather than post types?

    Would something like this work?:

    Perhaps this is worthy of another tutorial. Any additional help is greatly appreciated.

      • No, I decided to go with custom post types instead.

        If anyone has any insight, on this it would be greatly appreciated.

        The specific question is how to make something like this work using taxonomies instead of post types?

  13. Hi, you wouldn’t happen to also have a section to add maybe for those of us wanting to a dropdown menu search form interface rather than checkboxes? 

    • Yes!
      What Zach said…

      It would be ideal to have this “Advanced Form” be able to search through custom fields. You could make the ultimate search form this way. Any takers??? C’mon WP Beginner!!

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.