Support » Fixing WordPress » [Plugin: Relevanssi – A Better Search] Searching by taxonomy term

  • Hi!

    Firstly, thanks for a great plugin!

    I’m getting a little confused about filtering search results by a taxonomy term. Here’s what I’ve done so far:

    In Settings->Relevanssi I’ve scrolled down to “Custom taxonomies to index:” and filled in the taxonomy names here separated by a comma. I’ve then clicked save and rebuilt the index.

    I’ve then built a search URL to only include results from that taxonomy in the form ?s=my+search+term&post_type=product&product_series=the_name_of_a_series

    Unfortunately this doesn’t seem to be working (with or without the post type in the URL). Should I be referencing taxonomies by their ID or name (e.g. product_series vs. Product Series) in URLs and in the Settings? How about the terms? (e.g. the_name_of_a_series vs. The Name of a Series)

    Whatever I seem to doesn’t seem to affect the results (filtering by post type works fine). Any help you can offer would be great.

Viewing 10 replies - 1 through 10 (of 10 total)
  • That should work. I remember there were some problems with custom post types and custom taxonomies a long time ago, perhaps this is the same issue. Can you try if the taxonomy search works with regular posts or pages?

    Hmm, that doesn’t seem to work either. This is what I did:

    Applied a custom taxonomy to Pages.
    Set a page to use a term from that taxonomy.
    Tried a search like: ?s=destination&product_type=books

    The results don’t change with the addition of the product_type=books in the URL 🙁

    Does it work if you search for


    One possibly related bug that I’ve found:

    If you you add multiple tax_query parameters in pre_get_posts that use the term ID rather than the slug – Relevanssi fails.

    The error is being triggered on line 627 of /lib/search.php – $query->query_vars[“term”] isn’t set.

    My $wp_query has a taxonomy and a term_id query_var, but no term

    Hi Mikko,

    Thanks for your reply – unfortunately that URL doesn’t restrict the search either. Could there be some setting that I’ve missed? Either in the creation of the taxonomy or within Relevanssi?

    And you’re sure you’re actually getting results from Relevanssi? If you deactivate Relevanssi, do the results change?

    Phill, that’s a bug, yes. I’ll add that to my to-do list.

    Yeah, very sure. Deactivating the plugin changes the search results and I also have features like excluding by tag and weights working so I’m definitely getting back data from Relevanssi.

    Ok, I’ll have to investigate this a bit, but I’m quite busy with my job right now, so I can’t promise fast results.

    Hi Mikko – would it help if you could access the install’s admin panel? I can’t provide the URL on here but I could send you across some details via e-mail? Thanks for your help so far!



    Okay, we’ve done a little digging into the code and come up with these two issues. Firstly:

    Search.php line 179 produces:
    SELECT term_taxonomy_id FROM wp_terms JOIN wp_term_taxonomy USING(term_id) WHERE slug LIKE '%books%' AND taxonomy LIKE 'product_type'

    I’ve no idea why this is using wildcard LIKE queries, however because we have terms of books and ebooks this is only working for us because they come out of the database in the right order. If we’d added the terms in another order this would probably be broken.

    Search.php line 306: This is where the problem I describe above occurs:
    if (is_array($taxonomy))

    This isn’t evaluating to true so the taxonomy request is not being added to the WHERE of the search query

    So, we’ve added a new section underneath
    elseif (is_numeric($taxonomy) && $taxonomy > 0)
    to check to see if it’s actually a number rather than an array. Whether this is the best way to deal with that, or why $taxonomy isn’t an array I don’t know – however that’s how we’ve fixed it!

    Hope this helps!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Searching by taxonomy term’ is closed to new replies.