SearchWP Blog

WordPress Tutorials, Tips, and Resources to Help Grow Your Business

Are you wondering how to create a WordPress search form for custom post types?

If your site contains custom post types other than the default post types: pages or posts, WordPress can’t search them properly. Because, the default engine only indexes title and content, ignoring crucial information such as meta, taxonomies, etc.

Therefore, a separate search form for custom post types is necessary to properly index important data points. Otherwise, your visitors will not find what they’re looking for. 

So, in this step-by-step tutorial, we’ll show you how to create a WordPress search form for custom post types.

Key Takeaways:

  • Custom post types are what make WordPress so popular. 
  • WordPress does not index custom post types by default.
  • SearchWP makes custom post types, fields, and taxonomies searchable.

Why Create A WordPress Search Form For Custom Post Types?

By default, WordPress comes with two main content types—posts and pages. However, you’re free to create your own custom post types and add any custom fields. This is why WordPress has gained immense popularity and now powers more than 40% of all websites on the internet. 

Custom post types are very useful if you’re creating content that doesn’t fit within the boundaries of standard posts or pages. They open up endless possibilities for organizing your content in ways that make the most sense for your website’s goals.

Simply put, custom post types allow you to turn WordPress from a simple blogging platform into a full-fledged content management system.

For example, if you have a recipe blog, you might want to create a custom post type called “Recipe.” You can even add custom fields like ingredients, cooking methods, and preparation time to make the content more specific and tailored to your audience.

Here is an example of a custom post type at WPBeginner in their Deals section, where they showcase featured deals to their visitors.

How to Create a WordPress Search Form for Custom Post Types: Custom Post Type Example

Now, why should you create a search form that searches exclusively among certain custom post types? Because you can make it much easier for your visitors to find the content they’re looking for.

For example, if you add a search form that searches only for the “Recipe” custom post type. It ensures that visitors who type “chicken” as a search query will find chicken recipes only—not an article, news, or just a page about chicken.

Also, the native WordPress search completely ignores custom fields. This means that even though your visitors can find a chicken recipe, they still can’t search for specific meal ingredients.

That’s why creating a search form that searches custom post types, including custom fields, is necessary.

So, let’s show you how to create a WordPress search form for custom post types that also considers custom fields when searching.

How To Create A WordPress Search Form For Custom Post Types

The most efficient way to build a custom search form for WordPress is by using SearchWP. It’s the most powerful search plugin used by more than 60,000 websites to enhance the default WordPress search functionality.

SearchWP gives you the freedom to control how your site’s search engine works. It allows you to include or exclude specific post types, taxonomies, and even custom fields in your search results.

Here’s what you can do with SearchWP: 

  • On-site search activity tracking: SearchWP tracks all search queries and provides you with a comprehensive report on your site’s visitors’ search behavior.
  • Seamless WooCommerce integration: SearchWP allows you to not only make WooCommerce products searchable but also attributes, tags, reviews, and product media.
  • Searchable PDFs and documents: SearchWP can make PDFs and other types of office documents searchable, ensuring users get more accurate and comprehensive search results.

Creating a search form for all custom post types is similar, so today, we will create a search form that searches exclusively among the custom post type: Products. 

Even if you have other custom post types on your website, the process is exactly the same. So, let’s get started!

Step 1: Install & Activate SearchWP

Get your copy of SearchWP by choosing the package that fits your needs as different packages come with different features.

When the purchase is complete, log in to your Accounts page and download the plugin file from the Downloads tab.

How To Create A WordPress Search Form For Custom Post Types: Install & Activate SearchWP Step 1

Also, be sure to copy the license key from the same screen as you’ll require it for activating the plugin later.

How To Create A WordPress Search Form For Custom Post Types: Install & Activate SearchWP Step 2Once you have the plugin zip file, you can install and activate SearchWP like any other WordPress plugin.

When you activate the plugin, you’ll be greeted with a welcome screen to start the onboarding process. Click the “Start Onboarding Wizard” button, this will guide you through the initial setup.

How To Create A WordPress Search Form For Custom Post Types: Install & Activate SearchWP Step 3

Alternatively, you can activate SearchWP directly by visiting SearchWP > Add License Key.

How To Create A WordPress Search Form For Custom Post Types: Install & Activate SearchWP Step 4

On this page, paste the license key (which you copied earlier in the previous step) into the appropriate field and press “Verify Key” to complete the activation process.

How To Create A WordPress Search Form For Custom Post Types: Install & Activate SearchWP Step 5

Your licensing information will appear below once the key is successfully verified. 

How To Create A WordPress Search Form For Custom Post Types: Install & Activate SearchWP Step 6

That’s it. SearchWP has been configured successfully. Now, we are ready to configure the custom post type search engine.

Step 2: Set Up a New Search Engine for Your Custom Post Type

The next step is to add a new search engine to your site. Think of the search engine as a set of rules that determine how WordPress performs a search.

The good news is that once activated, SearchWP will start indexing the content on your site and replace the default WordPress search automatically. 

The default configuration indexes only posts, Pages, and Media files. However, you can modify the engine to customize the priority of specific posts or page attributes, add/remove search sources, exclude results, and more.

Using SearchWP’s Supplemental Engine we can create multiple search engines. Therefore, let’s leave the default settings as is and create a separate engine for custom post types.

So to create a dedicated search form only for the desired custom post type, visit SearchWP > Algorithm and click the “Add New” button. 

How To Create A WordPress Search Form For Custom Post Types: Configure Search Engine Step 1

From here, we need to select the sources we want this search engine to consider when performing the search.

For the purpose of this tutorial, we will create a search form that searches exclusively among the custom post type: Products. So, let’s uncheck all the boxes except “Products.” Name the Engine appropriately, then click “Done”.

How To Create A WordPress Search Form For Custom Post Types: Configure Search Engine Step 2

Please note: Any post type that is set to be public will be available as a source, so you just need to select the custom post type of your choice from here. That’s it. 

Whether your eCommerce store is built with WooCommerce or EDD, you can make the products searchable. And if you have any other custom post types on your website, you can make them searchable as well by following the steps below. 

Now, click “Save” to apply the changes. Our Engine setup is complete! 

How To Create A WordPress Search Form For Custom Post Types: Configure Search Engine Step 3

Step 4: Create a Custom Post Type Search Form

Next, we need to create a search form for the custom post type. SearchWP also makes this super easy! You just need to visit SearchWP > Search Forms and click “Add New.”

How To Create A WordPress Search Form For Custom Post Types: Create Custom Post Type Search Form Step 1

Now, pick a meaningful name for your search form, which will help you recognize it easily, and select a theme layout. 

How To Create A WordPress Search Form For Custom Post Types: Create Custom Post Type Search Form Step 2

Then, configure the search form according to your needs. All fields are pretty self-explanatory; however, if you need any help, follow this tutorial

How To Create A WordPress Search Form For Custom Post Types: Create Custom Post Type Search Form Step 3

The most important step here is to configure which engine this search form will use. So, let’s pick “Products,” as we have created this engine to search exclusively for our desired custom post type. Also, you can use the SearchWP search results page to show the search results, as it comes with advanced features

How To Create A WordPress Search Form For Custom Post Types: Create Custom Post Type Search Form Step 4

Finally, click “Save” to finish creating the Search Form. 

How To Create A WordPress Search Form For Custom Post Types: Create Custom Post Type Search Form Step 5

There are multiple ways to add this search form to a page. Click the “Embed” button next to “Save” to see available methods.

How To Create A WordPress Search Form For Custom Post Types: Create Custom Post Type Search Form Step 6

Let’s show you how to add the custom post type search form using the Gutenberg block. To do that, open the page where you want to place the search form in Edit mode. Then, click “Add block” in the designated location. 

How To Create A WordPress Search Form For Custom Post Types: Show Search Form Step 1

Next, find the “Search Form” block and select it. How To Create A WordPress Search Form For Custom Post Types: Show Search Form Step 2

Now, pick the search form you created earlier from the dropdown. 

How To Create A WordPress Search Form For Custom Post Types: Show Search Form Step 3Finally, click “Save/Publish” depending on your scenario.

How To Create A WordPress Search Form For Custom Post Types: Show Search Form Step 4

Step 5: Test Your Custom Post Type Search Form

Your new custom post type search form is now live! Let’s test it to make sure everything is working correctly. To do that, visit the page where you placed the search form and perform a search query.

If your search results are pulling only the custom post types you configured, then you’ve successfully set up your custom search form!

How To Create A WordPress Search Form For Custom Post Types: See Search Form in Action

Wrapping Up

The standard WordPress search ignores custom post types. However, you have learned how to create a WordPress search form for custom post types to address this issue. We hope you’ll be able to apply this knowledge and give your visitors a smooth search experience.

Grab your copy of SearchWP now if you’re ready to create your own search form for custom post types. 

Also, if you own an eCommerce WordPress site, it might be helpful for you to learn how to add a custom WooCommerce search widget.

author avatar
Saif Khan

A Better WordPress Search Experience

Get the best WordPress search plugin. Trusted by 50,000+ websites.

Get SearchWP Now
Multiple Search Engines Icon