I have 5 custom post types in my website and i need to make a search form for each one to show only results from it.
What should be in the search form to only show results from the custom post type which it came from? How do i redirect from each page to a specific page results?
<form role="search" method="get" action="https://wordpress.stackexchange.com/">
<input type="hidden" id="cat" name="paints_buildings" />
<input type="text" size="16" name="s" placeholder="Search" />
<input type="submit" value="Go" />
</form>
If you only want to search a particular post type include a hidden field with the name post_type
and the value set as the name of the post type you want to search:
<form role="search" method="get" action="https://wordpress.stackexchange.com/">
<input type="text" name="s" placeholder="Search">
<input type="hidden" name="post_type" value="post_type_name">
<input type="submit" value="Go">
</form>
Just replace post_type_name
with the actual name of your post type.
Now when you search the URL will look like this:
http://example.com/?s=search+term&post_type=post_type_name
And only return results from that post type.