WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
Searching by taxonomy term (11 posts)

  1. Incendiary
    Member
    Posted 1 year ago #

    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.

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

  2. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    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?

  3. Incendiary
    Member
    Posted 1 year ago #

    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.
    Reindexed.
    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 :-(

  4. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Does it work if you search for

    ?s=destination&taxonomy=product_type&taxonomy_term=books

  5. Phill Brown
    Member
    Posted 1 year ago #

    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

  6. Incendiary
    Member
    Posted 1 year ago #

    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?

  7. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  8. Incendiary
    Member
    Posted 1 year ago #

    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.

  9. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  10. Incendiary
    Member
    Posted 1 year ago #

    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!

  11. Incendiary
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic