Are you looking to add a separate, custom search form in WordPress and limit it to say, a specific Custom Post Type? Here’s how I did it:
1. Create a search form template
While you could paste the new form directly into a template, I chose to create a separate template to house the form: artwork-search.php (My custom post type is Artwork). This search function was designed to limit the results to only the Artworks Custom Post Type. Here is the HTML5 style form I used in this template:
The key is the ‘hidden’ input field. Change the value to your own custom post type name.
2. Load the template part into your template
Now you can load that file into your template using get_template_part : [php]<?php get_template_part( ‘search’, ‘artwork’ ); ?>[/php] The form will now appear an you can style it as you would normally. But what about the search results? What template gets used?
3. Post Type Archive template
To display the search results, WordPress will first look for archive-$posttype.php if you have it. Otherwise it will fall back to index.php. If you happen to use Hybrid Core you can also fall back to archive.php.
The great thing in my case is that I’d already styled the archive-artworks.php template, so my search results looked fantastic, appearing just as the normal artwork archive pages do.
I’ve seen some pretty complex tutorials for creating a separate search form in WordPress. This method worked for me and was overall pretty simple.
This method may or may not work using other WordPress content types. I tried adding a custom taxonomy to the hidden input, but it wouldn’t return any results.
Update: Sebastian points out in the comments that you may need to name your search file search-artwork.php. I use Hybrid Core which uses a modified template hierarchy which is why I named it the way I did.