Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter DanielMcQ

    (@danielmcq)

    I’m posting what I found here in case somebody else runs into this problem:

    Relevanssi will sanitize your taxonomy title as part of the sql generation that occurs in the relevanssi_search() method in relevanssi-premium/lib/search.php.

    If you have a taxonomy name like “English Subtitles”, it will get sanitized to “english-subtitles” and then Relevanssi won’t be able to find the related terms for that taxonomy.

    In my case, the sql query to find the terms for this taxonomy was constructed as

    SELECT tt.term_taxonomy_id
    FROM wp_term_taxonomy AS tt
    LEFT JOIN wp_terms AS t ON (tt.term_id=t.term_id)
    WHERE tt.taxonomy = 'english-subtitles' AND t.term_id IN (267)

    when it should have been

    SELECT tt.term_taxonomy_id
    FROM wp_term_taxonomy AS tt
    LEFT JOIN wp_terms AS t ON (tt.term_id=t.term_id)
    WHERE tt.taxonomy = 'English Subtitles' AND t.term_id IN (267)

    I’m relatively new to WordPress and have inherited an existing site, so I don’t know if there are standards for naming taxonomies. But it seems here that if you name your taxonomy in a way that will cause it to be different after sanitization, the query won’t work.

    Thread Starter DanielMcQ

    (@danielmcq)

    One follow up question would be, which array does Relevanssi use for taxonomy queries if “s” does have a value?

    $query->tax_queries[“queries”]
    or
    $query->query_vars[‘tax_query’]

    Thanks.

    Thread Starter DanielMcQ

    (@danielmcq)

    Hi Mikko,

    Ok, thanks for clarifying. So if we have a search form that has a search term field as well as fields for taxonomies that limit the search, if a user chooses to search just by a taxonomy, we need to use the standard WP search. We can only use Relevanssi if the “s” arg isn’t empty.

    I imagine I can do this using the method you’ve described in previous posts:

    remove_filter(‘the_posts’, ‘relevanssi_query’);
    remove_filter(‘posts_request’, ‘relevanssi_prevent_default_request’,9);
    remove_filter(‘query_vars’, ‘relevanssi_query_vars’);

    I guess the trick it to know where to check for s==”” and then run those remove_filter methods.

    Thread Starter DanielMcQ

    (@danielmcq)

    Hi Mikko,

    Thanks for your response. In this case, I wasn’t using a search term.
    The search form has a text field for search terms and then four controls corresponding to taxonomies : Video types (pulldown), video topics (pulldown), English subtitles (checkbox), Educator Resources (checkbox).

    In my test case I’m assuming the user wants to see all videos with english subtitles, so I’m selecting the “English subtitles” checkbox and submitting.

    The current code follows the example for creating multiple-taxonomy searches you posted here.

    I have a similar function that collects the four query args from the form and pushes them into the tax_query property.

    https://pastebin.com/aaLVDdBP

    You wrote “You can’t use Relevanssi to just fetch things by tax_query (also, that’s a huge waste of resources to do so, because you’re not using Relevanssi for anything).” So are you saying that if we’re trying to use these four fields to allow the user to limit results by different taxonomies, we shouldn’t use Relevanssi?

    Thanks for your quick response on the first post. Much appreciate your help.

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