Resources     Blog  

  1. Home
  2. WordPress Tutorials
  3. How to Add a WordPress Custom Search Form for Custom Post Types

How to Add a WordPress Custom Search Form for Custom Post Types

The search tool built into WordPress is very basic. It may show a few relevant search results, but it isn’t very efficient when it comes to more inclusive searches. You could edit code to alter how the search field works, but not everyone feels comfortable making those kinds of changes. Luckily it’s easy to improve your WordPress search results by adding a custom search form to your website.

In this tutorial, I’ll show you how to use the Ivory Search plugin to greatly enhance your website search. It allows you to create new custom search forms, as well as searching WooCommerce products and images, files, and attachments. You can even create different search forms to search for different types of content.

Finally, it lets you display your search forms anywhere on your site since it works in widgets and creates shortcodes. If you have been looking for a way to customize your WordPress site search, you’ve found it.

Let’s take a minute to install it, and then I’ll go over a few of the features.

Installing the Ivory Search Plugin

Log in to your WordPress admin panel.

In the left column navigation, mouse over the “Plugins” link and click the “Add New” link.

mouse over the "Plugins" link and click the "Add New" link

In the “Search plugins…” box, enter, “Ivory Search.”

search for the WordPress Ivory Search plugin

When you find the plugin, click the “Install Now” button.

click to install the WordPress Ivory Search plugin

Now the plugin is installed, but it has to be activated before you can use it.

Click the “Activate” button.

click to activate the WordPress Ivory Search plugin

That’s all there is to it. Now let’s put the plugin to work.

In the left column navigation, mouse over the “Ivory Search” link and click the “Settings” link.

click the "Settings" link

You can start creating new WordPress search forms without changing anything in the settings. But there are a few things that you may want to change.

Ivory Search WordPress plugin global settings

  • Custom CSS – You can add CSS here if the forms generated by the plugin need some tweaking to fit your site. Think of it like the “Additional CSS” field in the WordPress theme customizer.
  • Stopwords – Enter any words here that you want to exclude from search.
  • Synonyms – This is kind of a cool feature. Entering images = pictures here will return results for both words when only one is searched. “Images” and “pictures” are just used as an example. You can pair any words that may be related to your site.
  • Header Search – This toggles a search form on or off in the theme header—all of these default to off.
  • Footer Search – Toggles a search form on or off in the theme footer.
  • Mobile Search – Toggles a search form on or off in the mobile view of your site.
  • You probably won’t need the controls in Plugin Files or Advanced. They deal with turning search off for the entire site and loading CSS and JavaScript files. If you opt-out of loading the CSS and JavaScript, you have to add it to your theme manually. That’s an option for those of you who are into editing theme files and extreme site optimization. The rest of us should just let the plugin load the files.

In the Menu Search section, you’ll find controls to add search to your site menus. We’ll go over adding search forms to widgets and posts and pages using shortcodes in a minute. But if you want search in your menu, this is where you’d activate it.

Ivory Search WordPress plugin menu settings

In the Analytics section, you control whether searches are tracked in Google Analytics. It’s enabled by default. But if you don’t use Google Analytics (or don’t want to see search data there), you should disable this.

Ivory Search WordPress plugin analytics settings

Okay, let’s move on to the search forms themselves.

The Default Ivory Search WordPress Search Forms

In the “Ivory Search” section of the left column navigation, click the “Search Forms” link.

Ivory Search WordPress plugin default forms

There are a few forms that have been preconfigured and provided to use as templates (or as they are).

  • Custom Search Form – This is the standard form (what you’d get if you created a new form) customized to search image files.
  • Default Search Form – The default search form settings control the existing, built-in WordPress search form. So making changes here changes the behavior of the WordPress search.
  • AJAX Search Form – An AJAX search form displays search results as you type in the form. A nice option, but bear in mind that it consumes more website resources than a standard search form. An AJAX search may not perform well on a busy site with a limited amount of server memory.

Note that the sample search forms here can all be edited. Every form created with the plugin can be edited in a number of ways to perform different searches. This being a basic getting started tutorial, I’m not going to go into too much detail on those options. We’ll be using the sample search forms. But part of the beauty of the plugin is the editability and versatility of the forms it creates. So take some time to poke around and experiment.

I’ll demonstrate a couple of the different form types as we look at how to display them on your site. But first, let’s go back to that Default Search Form.

How the Default Search Form Works

I mentioned that the Default Search Form created by Ivory Search controls the existing WordPress search form on your site. This is how it works.

The standard WordPress search does not include media files. So a search for “remix” on our test site returns a post that contains the word “remix,” as expected.

Ivory Search WordPress plugin standard search results

But there’s an image name that includes “remix,” too. By editing the Default Search Form, we can include images in the search results.

Click “Edit” for the Default Search Form.

Ivory Search WordPress plugin editing default form

Then click the “Post Types” section. In the “Posts, Pages” drop-down, click “Media” to toggle it on.

Ivory Search WordPress plugin adding media to search

Now you can see that “Media” has been added to the “Posts, Pages” drop-down, but a new “Media” section appears too. You can use that section to configure which types of media are included in the search.

Click the “Save Form” button.

Ivory Search WordPress plugin click "Save"

Now, if we search “remix,” we see the image file included in the search results.

Ivory Search WordPress plugin image in search results

So as you can see, you can use the plugin simply by editing the Default Search Form. There’s no need to do anything else.

But of course, we want to do a bit more, so let’s add a search form in some other places.

Displaying Your Custom WordPress Search Forms in Widgets

In the left column navigation, mouse over the “Appearance” link and click the “Widgets” link.

The first thing we want to do is remove the WordPress search widget. We’re adding our own search form, and we don’t want two search forms in the footer.

Ivory Search WordPress plugin remove WordPress search widget

Scroll down and click to open the Ivory Search widget. Choose the widget area where you want to add a search form. Our test site theme only has a footer widget, so we’ll click the “Add Widget” button to add it there.

Ivory Search WordPress plugin click the "Add Widget" button

Now you can add a name to the widget, and choose one of your existing search forms to be displayed. Since we haven’t seen it yet, let’s use the AJAX form.

Ivory Search WordPress plugin choose search form

Click the “Save” button.

Now, if we go to the widget area of our site, the AJAX search is there. You can see the search results appear as you type.

Ivory Search WordPress plugin AJAX search results

Displaying Your Custom WordPress Search Forms Using Shortcode

You aren’t limited to widget areas. You can place a search form anywhere.

In the “Ivory Search” section of the left column navigation, click the “Search Forms” link. You’ll notice that each form has a shortcode associated with it.

Copy the shortcode for the search form you want to display.

copy the shortcode

Then paste it into a page or post.

Ivory Search WordPress plugin paste shortcode in page

Now when we save the page, the search form appears.

Ivory Search WordPress plugin search form on page

Creating Different Search Forms for Different Content Types and Taxonomies

A valuable feature of Ivory Search is its ability to create forms that search for very specific things. To see what I mean, we’ll edit the AJAX form we were just working with. But you can find these controls in any of the default forms, and any new form you create.

The area we want to look at it the “Extras” section. Open it up, and you’ll see several controls. Some of them are only available in the paid version of the plugin. But there are still a lot of features you can use for free.

extras section

By enabling or disabling the options, you can create your own custom search. There is an endless number of combinations.

  • Search post titles, contents, or excerpts.
  • Category titles and/or descriptions.
  • Posts with or without password protection.
  • Even posts within a specified date range.

Okay, there aren’t an endless number of combinations, I was exaggerating. But it’s a lot of combinations. 😉

What Happens if You Uninstall the Ivory Search Plugin

If you uninstall the plugin, pages, and posts that used the plugin will be affected.

  • Search forms created by the plugin will be deleted.
  • The plugin shortcodes will stop working, so the shortcodes themselves will be displayed as text anywhere they were used.

The above issues are what we found in our testing. There may be other issues our testing did not uncover.

Creating a Good WordPress Search Environment Is the Key to Keeping Visitors on Your Site

Getting visitors to your site is only the first step. You want to keep them around after they see what they came to see. A comprehensive and effective search system will help do that. After all, there’s no point in filling your site with great content if it can’t be found.

Have you ever had the need for a customized search on your website? Have you used any other WordPress search customization plugins?

Let me know in the comments. I’d love to hear from you.

Author: Michael Phillips

Michael Phillips is a web hosting industry veteran, helping people make the most of their web presence since 1995.

Was this article helpful?

Related Articles

Comments

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.