Last Updated on September 2, 2021 by Oluwatuyi
Do you want to create advanced search form in WordPress?
You can show your visitors a better website experience by adding a search form that includes your custom post types in the results
So we’ll show you step by step on how to create an advanced search form for custom post types in WordPress.
Reason to Create an Advanced Search Form for Custom Post Types in WordPress?
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.
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.
Create a New WordPress Search Algorithm using SearchWP Plugin
One of 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 40,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.
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.
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
Once you’re finished customizing your default search engine settings, make sure to click the ‘Save Engines’ button to create your first search engine.
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.
This will automatically create a new separate search engine.
Next, click the ‘Sources & Settings’ button.
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.
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.
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.
Next, type ‘HTML’ into the search box.
Then, select the ‘Custom HTML’ block.
Once you’ve done that, you can add the following shortcodes and HTML to your page.
[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> [searchwp_search_result_excerpt] [/searchwp_search_results] </div> <div class="no-search-results-found"> [searchwp_search_results_none] No results found, please search again. [/searchwp_search_results_none] </div> <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"] </div>
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.
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.
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.
If you have any issue on this, you can use our comment session or join our delegate on facebook to solve any issues related to WordPress and subscribe to our YouTube Channel for WordPress video tutorials.