• Hi everyone!

    In my website I’m using relevanssi and facetwp to search for products from the homepage and the products page. Everything works perfectly.

    Now I’d like to add e search form for posts on my blog page. The problem is that right now I get products and not posts as results.

    I’ve tought of two possible solutions:

    1) Add posts to relevanssi index, and then use one of the hooks to filter the results. I’m not sure what the easiest way to distinguish the searches query would be.

    2) Find a way to disable relevanssi and use the standard search for queries coming from my blog page. This would be my favourite option.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • No need for filter hooks, you can use the regular WordPress query parameters. Set “post_type” to “post” to get posts and “product” to get products.

    Just add

    <input type="hidden" name="post_types" value="post" />

    to the search form that targets posts and

    <input type="hidden" name="post_types" value="product" />

    to the search form that targets products. (These use “post_types” on purpose. It’s Relevanssi-specific version of “post_type” that works more reliably in some cases.)

    Thread Starter dariooddenino

    (@dariooddenino)

    Umm I see. Then I’d have to add regular posts to relevanssi indexing.

    I think the facetwp search might not work with this method, but I can manually alter the query somehow for that.

    Thanks

    You can use filters, for example pre_get_posts to add the parameter, if you can figure out a way to know which search form you’re modifying from the filter.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Relevanssi] Searching for different post types from different pages.’ is closed to new replies.