If you are coding your search form, below the search button add this field:
<input type="hidden" name="post_type" value="cpt-name" />
where ‘cpt-name’ is the name of your custom post type. That will show results only for that post type.
Then you’d have to use conditionals like
<?php
if ( is_archive() && ( get_post_type() == 'cpt-name' ) ) : // then
echo '<input type="hidden" name="post_type" value="cpt-name" />'
...and so on...
?>
does that work?
Thanks Alex,
Yes adding the hidden input with my CPT to the form field works to filter the CPT. I actually had it working great using checkboxes based on a few tutorials (like this one) I found online, but I ran into an error. I am also using Dave’s Live Search plugin to return search suggestions using ajax. Since I used a dynamically produced array for the input name, the ajax wasn’t grabbing it, because the array wasn’t filled until the search form was fired. (Hope that makes sense.)
My code is:
<input type="hidden" name="post_type[]" value="my-cpt" />
And I need it to be:
<input type="hidden" name="post_type" value="my-cpt" />
for the ajax to work. Hmm…
like a drop-down filter that the user can use to select what post type they are searching for?
somewhat unrelated, but I’ve used this page as a good way to understand how to filter the searches through my search form, if it helps:
http://wordpress.org/plugins/relevanssi/faq/
read further down the page…
good luck !
Sorry, I changed my post halfway thru my thought process! 😛
Yes, that FAQ is great, but I’m a bit of a PHP noob, especially when it comes to this search stuff.
I combined the concept on this other WP forum post on Relevanssi and this tutorial on search checkboxes and had great results. It was working like a charm. But then I tried getting Dave’s WordPress Live Search plugin to play nice and it only works when when the hidden input type is set to:
<input type="hidden" name="post_type" value="my-cpt" />
whereas my code to get the above to work together is:
<input type="hidden" name="post_type[]" value="my-cpt" />
I’m also new to this stuff… so hopefully someone else a little more knowledgeable comes along 🙂
good luck!
How is your code dependent on the post_type being an array? Relevanssi wont’ take an array for post_type anyway, but wants a comma-separated string.
Anyway, my understanding has been that Dave’s Live Search is not at all compatible with Relevanssi in the first place, but great if that’s not the case anymore.