SearchWP Blog

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

Creating a WordPress search form for custom post types is one of the most common requests we hear from site owners.

If your site contains custom post types other than the default posts or pages, WordPress won’t search them the way you’d expect.

Its built-in search looks at each post’s title, excerpt, and content, so it doesn’t search custom fields or taxonomy terms directly.

That’s why a separate search form for custom post types is the dependable fix. Otherwise, your visitors won’t find what they’re looking for, and they’ll leave for Google instead.

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

Key Takeaways:

  • A custom post type search form returns only the post types you choose, so a recipe search shows recipes and nothing else.
  • WordPress’s built-in search doesn’t search custom fields or taxonomy terms themselves, and it gives you no dashboard setting to scope a search form to one post type.
  • SearchWP makes custom post types, custom fields, and taxonomies searchable, and it lets each form use its own search engine.
  • Everything in this tutorial is included in SearchWP’s Standard license, so there’s no upgrade to buy partway through.

Why Create a WordPress Search Form for Custom Post Types?

By default, WordPress ships with two main content types: posts and pages. You’re free to create your own custom post types and add any custom fields you need.

Custom post types are useful when you’re publishing content that doesn’t fit inside a standard post or page. They let you organize your content around what your site does.

Put simply, custom post types turn WordPress from a blogging platform into a full-fledged content management system.

For example, if you run a recipe blog, you might create a custom post type called Recipe.

You can then add custom fields like ingredients, cooking method, and preparation time to make each entry more specific and useful to your audience.

A form that lets visitors search only custom post types you pick makes the right content easier to find.

Say you add a search form that searches only the Recipe post type.

Visitors who type “chicken” will find chicken recipes only, not an article, a news post, or a page about chicken.

From our experience, this is the change site owners notice first, because the results finally match what the person was looking for.

What Default WordPress Search Gets Wrong Here

Before we get to the setup, it helps to know exactly where the built-in search runs out of road.

We’ve worked with many site owners who spent weeks blaming their theme for this.

  • One search covers the whole site. WordPress runs a single query across your content types at once, so a visitor looking for a recipe still gets pages, posts, and products mixed into the same list. There’s no setting in the dashboard that says “this form only returns recipes.”
  • Custom fields aren’t part of the search. WordPress doesn’t search custom fields by default, so an ingredient, a SKU, or an agent name stored in its own field won’t match what someone types. On a recipe site, that means searching “paprika” finds nothing unless the word also happens to sit in the title or body copy.
  • Taxonomy terms aren’t searched either. WordPress’s built-in search doesn’t search taxonomy terms themselves, so a recipe filed under a “Thai” cuisine term only surfaces if “Thai” also appears in its title, excerpt, or content. So the taxonomy you built to organize content isn’t pulling any weight in search.
  • You can’t control what counts most. WordPress nudges title matches up the list and excerpt matches above body matches, but that order is fixed and no dashboard setting changes it. There’s no way to say an ingredient match matters more than a passing mention halfway down a page.

There’s one more wrinkle worth knowing about.

A custom post type can be registered to stay out of search results entirely, and plenty of plugins register their post types that way.

When that happens, no amount of tweaking your theme’s search template will bring that content back.

The good news is that all four of these gaps close with the same setup, and it doesn’t involve writing any code.

Create a WordPress Search Form for Custom Post Types

The most reliable way to build a custom post type search form is with SearchWP.

SearchWP, the best WordPress search plugin

SearchWP is the best WordPress search plugin, trusted by 50,000+ website owners.

It puts you in control of what gets indexed, what gets searched, and how much each field counts toward the results.

Here are the SearchWP features that matter most for this job:

  • Multiple search engines. You can run more than one search engine on the same site, each with its own sources and rules. That’s what lets a recipe form and your main site search behave completely differently.
  • Custom field and taxonomy indexing. SearchWP can index custom fields and taxonomy terms alongside the title and content, so the data you’ve attached to each entry becomes searchable.
  • A search form builder. You can build and style search forms in the dashboard, then place them with a block or a shortcode. No template files, and no code.
  • Relevance weights you control. Every searchable field gets a weight, so you decide whether a title match outranks a match buried in a custom field.

With that, let’s see how you can use SearchWP to build a search form for your custom post types.

Step 1: Install and Activate SearchWP

To start, head over to the SearchWP website and sign up for an account by choosing the plan that fits your site.

Everything in this tutorial works on the Standard plan, so there’s no need to size up for it.

Once you’ve signed up, log in to your account and open the Downloads tab.

From there, download the SearchWP ZIP file to your computer.

Download SearchWP plugin from account area

Be sure to copy your license key from the same screen, since you’ll need it in a moment.

Next, you can install and activate SearchWP like any other WordPress plugin.

After activating, you’ll land on a welcome screen that offers to walk you through setup.

Go ahead and click Start Onboarding Wizard to follow the guided setup, which includes pasting in your license key.

SearchWP onboarding wizard welcome screen

SearchWP is all set. You’re ready to build the search engine that powers your custom post type form.

Step 2: Create a Search Engine for Your Custom Post Type

Think of a search engine as a set of rules that decide how a search is performed.

SearchWP creates a default engine during setup, and that engine takes over your main site search.

Rather than change it, you’ll add a second one. SearchWP calls this a supplemental engine, and it leaves your existing site search exactly as it is.

To begin, navigate to SearchWP » Algorithm from your WordPress dashboard.

This screen is titled Engines, and it lists every engine on your site.

Next, click Add New to create your second engine.

add a new search engine in SearchWP

SearchWP opens the Sources & Settings panel for the new engine right away, so there’s nothing to go hunting for.

The panel opens on a Sources list with a checkbox for every available source.

Here’s where the scoping happens. Uncheck everything except your custom post type, which in our case is Recipes.

Then scroll past that list to Options, and give the engine a clear name in the Engine Label field, something like “Recipes”, so you can recognize it later.

select a custom post type as a SearchWP search source

When you’re finished, click Done to close the panel.

Note: Any post type registered as public shows up here as an available source. That includes post types WordPress leaves out of its own search results, which is why SearchWP can reach content your theme’s search never could.

Your engine now searches recipes only, but it’s still looking at the same fields WordPress would.

To fix that, find your Recipes source and click Add/Remove Attributes.

A panel opens named after your source and engine, so ours reads Manage Recipe Attributes (Recipes Engine).

This is where you choose which fields the engine actually reads.

Under the Custom Fields heading, pick the meta keys you want searched, which for us are the ingredients, cooking method, and preparation time.

make custom fields searchable for a custom post type

Then do the same under Taxonomies, selecting your cuisine and course taxonomies so their terms become searchable.

Go ahead and click Done to save your picks and close the panel.

Back on the source, the sliders under Applicable Attribute Relevance control how much each field counts.

Title already sits at the top of the scale by default, and each custom field starts at the bottom.

You’ll see one slider per meta key you added, so you can nudge a single field like ingredients upward without letting it outrank a Title match.

set attribute weights in a SearchWP search engine

Once the weights look right, click Save in the top right corner.

Finally, click Rebuild Index so SearchWP indexes the fields you just added.

Your browser will ask if you’re sure you want to rebuild the index, so confirm the prompt to start the rebuild.

Skipping the rebuild is a common reason a new attribute seems to do nothing, and you can read more about engine configuration in the SearchWP engines documentation.

Step 3: Create the Search Form and Add It to Your Site

With the engine ready, you can build the form your visitors will actually use.

To get started, go to SearchWP » Search Forms and click Add New.

create a WordPress search form for custom post types

Give the form a name you’ll recognize, then pick a layout under Choose a theme.

The Layout Theme options are Basic, Category Search, Quick Search, Advanced Search, and Combined.

We went with Basic here, since a single scoped search box is all this form needs to do.

configure a custom post type search form in SearchWP

Now scroll down to the Custom Styling section, which holds the form’s behavior settings as well as its appearance.

The most important setting here is which engine this search form will use.

Set the Engine dropdown to the engine you built in Step 2, which is our “Recipes” engine.

connect a search form to a custom post type search engine

This one dropdown is what makes the form a custom post type search form rather than another site-wide search box.

Right below it, the Results Page setting decides where visitors land after searching.

Choosing Site Default sends them to your theme’s search results page, while SearchWP uses SearchWP’s own results page, which comes with layout and styling controls of its own.

Picking SearchWP also reveals a Target Page setting just below, where you choose the page that will host those results.

You can also set the Placeholder text so the box reads something like “Search recipes” instead of the generic default.

If you want to go further with filters and dropdowns on the form itself, see our guide on advanced search forms in WordPress.

When the form looks right, click Save.

Then click Embed to see how to place it on your site.

embed a SearchWP search form on a WordPress page

SearchWP asks whether you want to use an existing page or create a new one. We already have a page ready, so click Select Existing Page, choose it from the Select a Page dropdown, then click Let’s Go!

Once the page opens in the editor, add the SearchWP Form block where you want the search box to appear. You’ll find it under the SearchWP block category.

Then pick your form from the block’s dropdown.

add a custom post type search form with a Gutenberg block

Finally, publish or update the page.

Pro Tip: Every form gets a shortcode, listed in the Shortcode column on the SearchWP » Search Forms screen. It’s the quickest way to drop the same form into a widget area, a sidebar, or a page builder layout.

Step 4: Test Your Custom Post Type Search Form

Your custom post type search form is live, so let’s confirm both halves of the setup are working.

Visit the page where you placed the form and run two searches.

First, search for “chicken”.

Every result should be a recipe, with no blog posts, pages, or unrelated content mixed in. That confirms the engine is correctly scoped to your custom post type.

Next, search for an ingredient that appears only in a custom field and never in a recipe title, like “paprika”.

If the recipes using paprika still come back, your Custom Fields attribute is indexed and working.

WordPress search form returning custom post type results only

If the first search passes but the second returns nothing, the usual cause is a missed Rebuild Index after adding the attribute.

Our guide on what to do when custom post type search isn’t working walks through the other things to check.

Bonus: Add Live Results and Filters to Your Search Form

Once the form works, there are two upgrades worth knowing about.

The first is live search, which drops matching results into a dropdown as visitors type instead of making them load a results page.

You can install it from SearchWP » Extensions by finding the Live Search card, and the plugin itself is called SearchWP Live Ajax Search. It’s included with Standard and up, so it’s available on the same license this tutorial uses.

The second is filtering, which works well when your custom post type has taxonomies worth browsing by.

WPFilters (All Access) adds facet-style filters to a results page, and our guide on adding a filter sidebar to WordPress search results shows what that setup looks like.

Frequently Asked Questions

1. Does WordPress search custom post types by default?

Public custom post types can appear in WordPress search results, but the built-in search only looks at the title, excerpt, and content of each entry. It doesn’t search custom fields or taxonomy terms themselves, and there’s no setting to limit a form to one post type. Some post types are also registered to stay out of search results entirely.

2. Can I create a search form that only searches one post type?

Yes, and that’s exactly what this tutorial builds. In SearchWP, you create a second engine under SearchWP » Algorithm, use Sources & Settings to select only your custom post type, then set the Engine dropdown on your form to that engine. We’ve used this to run a recipe search and a site-wide search on the same site without them interfering.

3. How do I make custom fields searchable in WordPress?

You’ll want to click Add/Remove Attributes on your source in the engine editor, then pick the meta keys you want searched under the Custom Fields heading, or choose Any Meta Key to include all of them. From there, click Save and then Rebuild Index so the field data gets indexed. Our guide on adding WordPress custom fields search covers the details, including how to include ACF fields in WordPress search.

4. Can I have more than one search form on the same site?

You can, and each form can point at a different engine. A recipe form can search recipes while your header search covers everything, because the Engine setting is saved per form. Our guide on adding multiple search forms to your WordPress site shows how to manage several at once.

Wrapping Up

You’ve now built a search engine scoped to a single custom post type, indexed its custom fields and taxonomies, and placed a form that searches nothing else.

We hope this article helped you learn how to create a WordPress search form for custom post types.

You may also want to see our guides on adding WordPress custom fields search and customizing the WordPress search results page.

Ready to make your custom post types easy to find? You can get started with SearchWP here, backed by a 14-day money-back guarantee.

author avatar
Aazim Akhtar

Create a Better WordPress Search Experience Today

Never lose visitors to unhelpful search results again. SearchWP makes creating your own smart WordPress search fast and easy.

Get SearchWP Now
Multiple Search Engines Icon