• Using Relevanssi and am very happy so far, thanks!

    I am trying to customize my search results so that when on the archive for a specific post type (say cats) the plugin only searches posts that belong to the cats post type, but when on another post type (say dogs), only dog posts will come up. I also have a separate page template I’m using where I’d like to search BOTH dogs and cats, but exclude blog (standard WP posts) and page results. How would I do this?

    Thanks!

    http://wordpress.org/extend/plugins/relevanssi/

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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?

    Thread Starter lilqhgal

    (@lilqhgal)

    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 !

    Thread Starter lilqhgal

    (@lilqhgal)

    Sorry, I changed my post halfway thru my thought process! 😛

    Thread Starter lilqhgal

    (@lilqhgal)

    Yes, that FAQ is great, but I’m a bit of a PHP noob, especially when it comes to this search stuff.

    Thread Starter lilqhgal

    (@lilqhgal)

    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!

    Plugin Author Mikko Saari

    (@msaari)

    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.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Search different post types on different pages?’ is closed to new replies.