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="/">
  <input type="hidden" id="cat" name="paints_buildings" />
  <input type="text" size="16" name="s" placeholder="Search"  />
  <input type="submit" value="Go" />

1 Answer 1


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="/">
    <input type="text" name="s" placeholder="Search">
    <input type="hidden" name="post_type" value="post_type_name">
    <input type="submit" value="Go">

Just replace post_type_name with the actual name of your post type.

Now when you search the URL will look like this:


And only return results from that post type.

  • Forgot to mention but actually my search form is inside a single page so my URL is example.link/post-type/single-post-name/?s=search+term is there a way to avoid this?
    – Asaf Hadad
    Commented Jul 30, 2018 at 10:58
  • Avoid what? Your URL or mine? Where the search form is has nothing to do with the results URL. The results URL is determined by the action attribute of the form. Commented Jul 30, 2018 at 11:01
  • i was missing the name="post_type" and that's why i got results from other places too.. works great now! thanks.
    – Asaf Hadad
    Commented Jul 30, 2018 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.