WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] Searching in posts that have BOTH CatA AND CatB (intersection (9 posts)

  1. arislikno
    Member
    Posted 2 years ago #

    Till now, we have been using the built-in WP ability to search in multiple categories by adding them in the URL.

    For example, we have the following two categories:

    likno-web-accordion-builder
    knowledge-base

    When we wanted to search for posts that contain the word “hello” and belong to BOTH categories (logical AND), we were writing (through our own code) the following URL:

    http://www.likno.com/blog/category/likno-web-accordion-builder+knowledge-base/?s=hello

    We currently evaluate your plugin and it seems that now that your plugin is active, this particular feature stops working.

    Your search will return results from the first category only, completely ignoring any other categories we added to the URL.

    Do you believe this is something that you can fix in your code?

    Thank you.

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

  2. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    Yeah, that doesn't work, because if you do that, $wp_query->query_vars['cat'] will only contain the first category. I don't know how the default WP search makes it work, but from Relevanssi's point of view, the second parameter just doesn't exist.

    http://www.example.com/?s=hello&cats=XX,YY

    does work, where XX and YY are category ID numbers.

    Since the extra categories don't appear in the query_vars, there's not much I can do to make that kind of syntax work.

  3. arislikno
    Member
    Posted 2 years ago #

    @msaari:

    Thank you for your prompt reply.

    I tried the “cats=xx,yy” method, but this does not work because the goal is to find posts that exist in BOTH categories (XX && YY) at the same time, not all posts of category XX and all posts of category YY.

    The default WordPress search allowed us to achieve this through this technique:

    http://www.likno.com/blog/category/likno-web-accordion-builder+knowledge-base/?s=hello

    Couldn't relevanssi "respect" this *existing* feature of WordPress, through an addition to its code?

    Thank you again.

  4. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    Well, yes, that works in default WP search, but like I said, WordPress doesn't pass the second category in query_vars, so I can't access it in Relevanssi. WordPress doesn't support respecting this technique.

    I'll see about adding the category intersection in the next version, it shouldn't be too tricky.

  5. arislikno
    Member
    Posted 2 years ago #

    OK, thanks for the reply.

    I misunderstood what you told me in your previous post about WordPress not passing the parameters to your plugin.

    It would be great if you can do this independently within your plugin in the next version, as mentioned by you.

    I have also sent you a small donation by PayPal, mostly for your kindness to reply fast and consider this addition (while not obliged to do so).

    Thanks.

  6. davetrow
    Member
    Posted 2 years ago #

    This capability would be a huge help with an online bookstore I'm helping build, as well, to deal with all the possible genres a book can belong to.

  7. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    Well, it is possible – I just worked on a job search like that last weekend – but it takes a different approach. If you have a way to pass multiple categories, you can then make Relevanssi return intersections or unions, whatever you want, by filtering the search results with the relevanssi_hits_filter filter hook.

  8. Goce Mitevski
    Member
    Posted 1 year ago #

    Hi Mikko,

    Any examples available from your assignment for this? I'm also trying to figure out a way to let Relevanssi know when I'm searching within two or more categories. I guess if 'category__and' is set, Relevanssi should automatically recognize that the search should include results that match every category specified in 'category__and' for WP_Query.

  9. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Like Goce noticed, Relevanssi doesn't actually support category__and at the moment. It will do so, in the next version.

    Also, much of the stuff earlier in the thread has been resolved by Relevanssi 3.1, which has support for WP_Query.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags