What’s your search term? That matters as well, Relevanssi requires you to include a search term. 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).
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.
http://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.
If you don’t have a search term, you don’t have a search, and Relevanssi can’t help you.
WordPress has good tools for fetching posts by taxonomy, and using something else just adds unnecessary overhead without providing anything useful.
There are solutions to make searches work without a search term, but that involves writing code that fetches the required posts manually, using the aforementioned WordPress tools, when there is no search term present.
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.
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.
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.
Relevanssi uses either $wp_query->tax_query or $wp_query->query_vars[‘tax_query’]; the first is what WP creates, the second is what users create.
That’s a bug you’ve found, by the way, that sanitize_title() there is wrong. I’ll have to fix it in the next version. Thanks!