👋🏼Welcome to my WP-Host blog where I am excited to share my knowledge and expertise on WordPress hosting and website construction tutorials with you. Let’s connect and learn from each other! You can reach me at info@yrshare.com.
How to Create an Advanced Search Form for a Word Press Custom Post Type?This article explains how to create an advanced search form for custom post types in WordPress. The main topics covered include:
The need for an advanced search form and its advantages.
Creating custom fields with the Advanced Custom Fields plugin to collect more useful search information.
Using the Query Monitor plugin to view generated SQL query statements for optimizing search performance.
Writing custom code to handle search form submission and constructing search queries based on user search criteria.
Displaying search results and enabling pagination.
Adding a search form with custom post types to your wordpress site search results can provide a better site experience for your visitors. In this WordPress tutorial, you can learn how to create an advanced search form for a WordPress custom post type.
Table of Contents
Why Create a Word Press Custom Post Type Advanced Search Form?
If you have many different content types, a custom post type search form allows you to help your visitors find the most relevant content more easily.
If we add a custom post type search form to each page, then the search results will only show posts of that category.
This custom search helps your visitors view more pages and stay on your site longer, which sends positive WordPress SEO signals like lower bounce rates and increased dwell time.
Create New Search Algorithms Using a Word Press Plugin
The easiest way to create an advanced search form for a custom post type is to use the Search WP plugin (now acquired by Awesome Motive), which is already used by tens of thousands of websites. It’s easy to use and gives you complete control over your Word Press search results.
The first thing you need to do is install and enable the plugin. Once enabled, you need to go to Settings » Search WP and 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 Search WP website. Once done, you need to click on the “Engines” menu option.
This will take you to a screen where you can set your search engine settings. Think of it as your website creating its own Google search algorithm.
With Search WP, you need to create a site-wide search engine before you can create a custom article type search engine, so we’ll do that first. You can adjust your search engine settings by clicking the drop-down menus for Articles, Pages, Library, or other custom article types. Each section has a “Weight Multiplier” that will change how search engines rank the content. If you want search engines to give importance to page titles rather than content, adjust the sliders accordingly.
When you’re done customizing your default search engine settings, be 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 type.
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 targets just the type of custom article you want. First, navigate to Settings » Search WP and click on the “Add New” button.
This will automatically create a new standalone search engine. Next, click the “Sources & Settings” button.
This will bring up a popup where you can choose the source of your custom search engine. Just uncheck the boxes for the sources you don’t want to include. In this example, we’ll just check the “Coupons” box because we want to create a search form that only allows users to search our coupons page.
You also need to give your search engine a name. Make a note of the name in the [Engine Name] box as you will need it in a later step.
Then, click the “Done” button. When you’re done, click the “Save Engines” button to save your new custom post type search engine.
Now, you need to download the Search WP Shortcode extension to easily add your new custom article search form to Word Press. First, head to the Search WP Shortcodes Extension website and click on the “Download available with active license” button.
Afterwards, you need to install and enable the extension the same way you installed the plugin above. You can now create new custom article search form pages using shortcodes.
Just navigate to Pages » New Page and give your page a name. After that, click on the plus “Add Block” icon to bring up the block menu.
Next, type “HTML” into the search box. Then, select the “Custom HTML” block.
Once done, you can add the following shortcodes and HTML to your page.
The code above will add your search engine, create a section to display the search results, display a no result message if necessary, and add pagination if the results go to multiple pages.
You need to change the engine name from [engine=”coupon”] to your own engine name. The rest of the code can remain unchanged.
Make sure you click Publish or Update to save your page and make it live. Your custom article type search engine is now live on your website.
Search WP is a very flexible and customizable search plugin. You can also use this plugin to add live Ajax search, create search by category functionality, and more. We hope this tutorial helped you learn how to create a Word Press custom post type advanced search form to further enhance your website search experience.
【WordPress Hosting / 悦然wordpress建站】I am a WordPress hobby from China, and I like to communicate with friends from all over the world to learn WordPress website building and maintenance related knowledge.