Relevanssi not functioning
-
I’ve used the free version of Relevanssi for a year or more with no problems at all. Then I had to change my woocommerce theme (old one discontinued) to Storefront with a child them. Relevanssi does not function. Only woocommerce product search is working.
I’ve been trying to fix the query in search.php but no luck. Maybe I’m not doing it right. Also checked for plugin interference.
I’ve included the search.php. Maybe someone could check it out and give me some help and directions.
Storefront search.phpThanks
The page I need help with: [log in to see the link]
-
No problems with the search results template, it looks perfectly normal.
Do you have a complete index? Can you show me screenshots of your Relevanssi indexing and searching setting pages, please?
Everything seems good there.
Please do the first two steps as described on this Relevanssi KB page. What kind of results you get?
Ok Mikko,
I did the the two steps, nothing jumps out as being wrong but then, I’m not sure what i’m looking at. So I just pasted them in –This is the search results from “Look at the parameters Relevanssi is getting”
array(71) { [“s”]=> string(15) “Hospital sheets” [“post_type”]=> string(7) “product” [“error”]=> string(0) “” [“m”]=> string(0) “” [“p”]=> int(0) [“post_parent”]=> string(0) “” [“subpost”]=> string(0) “” [“subpost_id”]=> string(0) “” [“attachment”]=> string(0) “” [“attachment_id”]=> int(0) [“name”]=> string(0) “” [“static”]=> string(0) “” [“pagename”]=> string(0) “” [“page_id”]=> int(0) [“second”]=> string(0) “” [“minute”]=> string(0) “” [“hour”]=> string(0) “” [“day”]=> int(0) [“monthnum”]=> int(0) [“year”]=> int(0) [“w”]=> int(0) [“category_name”]=> string(0) “” [“tag”]=> string(0) “” [“cat”]=> string(0) “” [“tag_id”]=> string(0) “” [“author”]=> string(0) “” [“author_name”]=> string(0) “” [“feed”]=> string(0) “” [“tb”]=> string(0) “” [“paged”]=> int(0) [“meta_key”]=> string(0) “” [“meta_value”]=> string(0) “” [“preview”]=> string(0) “” [“sentence”]=> string(0) “” [“title”]=> string(0) “” [“fields”]=> string(0) “” [“menu_order”]=> string(0) “” [“embed”]=> string(0) “” [“category__in”]=> array(0) { } [“category__not_in”]=> array(0) { } [“category__and”]=> array(0) { } [“post__in”]=> array(0) { } [“post__not_in”]=> array(0) { } [“post_name__in”]=> array(0) { } [“tag__in”]=> array(0) { } [“tag__not_in”]=> array(0) { } [“tag__and”]=> array(0) { } [“tag_slug__in”]=> array(0) { } [“tag_slug__and”]=> array(0) { } [“post_parent__in”]=> array(0) { } [“post_parent__not_in”]=> array(0) { } [“author__in”]=> array(0) { } [“author__not_in”]=> array(0) { } [“orderby”]=> string(9) “relevance” [“order”]=> string(4) “DESC” [“meta_query”]=> array(0) { } [“tax_query”]=> array(2) { [“relation”]=> string(3) “AND” [0]=> array(4) { [“taxonomy”]=> string(18) “product_visibility” [“field”]=> string(16) “term_taxonomy_id” [“terms”]=> array(1) { [0]=> int(1418) } [“operator”]=> string(6) “NOT IN” } } [“wc_query”]=> string(13) “product_query” [“posts_per_page”]=> int(24) [“ignore_sticky_posts”]=> bool(false) [“suppress_filters”]=> bool(false) [“cache_results”]=> bool(false) [“update_post_term_cache”]=> bool(true) [“lazy_load_term_meta”]=> bool(true) [“update_post_meta_cache”]=> bool(true) [“nopaging”]=> bool(false) [“comments_per_page”]=> string(2) “50” [“no_found_rows”]=> bool(false) [“search_terms_count”]=> int(2) [“search_terms”]=> array(2) { [0]=> string(8) “Hospital” [1]=> string(6) “sheets” } [“search_orderby_title”]=> array(2) { [0]=> string(168) “wrd_posts.post_title LIKE ‘{7a79222a4ef29dd29e2141ffc9afea18f84b04677bd6e665beeea14e482cb3bd}Hospital{7a79222a4ef29dd29e2141ffc9afea18f84b04677bd6e665beeea14e482cb3bd}'” [1]=> string(166) “wrd_posts.post_title LIKE ‘{7a79222a4ef29dd29e2141ffc9afea18f84b04677bd6e665beeea14e482cb3bd}sheets{7a79222a4ef29dd29e2141ffc9afea18f84b04677bd6e665beeea14e482cb3bd}'” } }
Search results from MySQL query
string(667) “SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 8 + relevanssi.content * 2 + relevanssi.comment * 0.75 + relevanssi.tag * 1 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 1 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf FROM wrd_relevanssi AS relevanssi WHERE relevanssi.term = ‘choosing’ AND relevanssi.doc NOT IN (SELECT DISTINCT(tr.object_id) FROM wrd_term_relationships AS tr WHERE tr.term_taxonomy_id IN (1418)) AND ( relevanssi.doc IN ( SELECT DISTINCT(posts.ID) FROM wrd_posts AS posts WHERE posts.post_type IN (‘product’) ) )”
And the third steo – “Look at the results” –
array(5) { [1056]=> float(182.003433521) [1221]=> float(91.0017167605) [1292]=> float(91.0017167605) [1337]=> float(91.0017167605) [7484]=> float(91.0017167605) }
What do you see? Any errors? Something missing? Anything wrong?
Suggestions?I do appreciate you time,
GregThere’s nothing unusual there, indeed, just the typical WooCommerce product visibility filter being added. The search is also restricted to just products, as is usual for WooCommerce.
The search also seems to find results now. Is Relevanssi still active? Are the any particular searches that are not producing results as expected?
Relevanssi is active.
I’m wanting to get posts results. Example: when searching for “How to choose a wheelchair” , which we have numerous articles, when get products.It seems something is blocking relevanssi. It’s active but not showing up in results.
“The search is also restricted to just products, as is usual for WooCommerce.”
This perhaps is the problem. I do not want woocommerce to restrict searches to products.
I’d like to include posts and pages.I checked the added code to the functions.php
add_filter( ‘relevanssi_modify_wp_query’, ‘rlv_force_post_product’ );
function rlv_force_post_product( $query ) {
$query->query_vars[‘post_types’] = ‘post,product’;
return $query;
}It looks just like above
Can’t help but feel I’m missing something – :o(
Your theme search form includes this:
<input type="hidden" name="post_type" value="product">That sets the post type restriction.
You can definitely get non-product results out of Relevanssi if you remove the post type restriction, like this: https://www.caregiver-aid.com/?s=wheelchair
The code you have is correct, but since your non-product posts are not posts, but pages, it needs to look like this:
add_filter( 'relevanssi_modify_wp_query', 'rlv_force_post_product' ); function rlv_force_post_product( $query ) { $query->query_vars['post_types'] = 'page,product'; return $query; }Do note that your theme search results template depends on the post type setting; if you remove the product post type setting, you’re not seeing the product results template anymore, and the results will look like this: https://www.caregiver-aid.com/?s=oximeter
That’s common with WooCommerce themes.
Mikko,
Sorry to be such a pain,.. but I’m still not there. I think the problem maybe in the Storefront theme.Let me explain.
I used the code you gave me from your last comment, and I tested my site.
(I have Storefront theme and Pharmacy child theme, both from Woothemes)I tested the search results with the code installed and uninstalled, one at a time, in Storefront and then in the child theme. Never in both places at once.
There was never any change in the search results, with or with-out code.
Then – I went to appearance > themes. Did a live preview of Twenty Fourteen theme and got good search results. Both products and posts displayed, with-out adding the code.
My problem must be in Storefront theme, preventing posts and products together in on search result. Probably blocking Relevanssi.
I’m thinking I may need to hire some help to achieve the desired results, my skills are somewhat limited. Thank you for your patience.
Do you have ideas or advice?
Here’s a code that makes WooCommerce search form not include the post type restriction:
add_filter( 'get_product_search_form', 'rlv_remove_post_type_restriction' ); function rlv_remove_post_type_restriction( $form ) { $form = str_replace( '<input type="hidden" name="post_type" value="product" />', '', $form ); return $form; }That might help too.
The problem is indeed related to your theme and WooCommerce. Storefront uses the WooCommerce product search form, which includes the post_type restriction. The filtering function I gave you should fix it and remove the post type restriction; if it doesn’t, I’m not sure why.
However, there’s no reason why Storefront can’t show all post types in the search results: https://www.caregiver-aid.com/?s=wheelchair is a search from your site with all post types included.
But yeah, hiring a developer may be a good idea, as that search results template is not very pretty for a mix of products and other pages. Any skilled theme developer should be able to help you sort this out.
Hey Mikko,
That last code you gave worked great. I’ve got some tweaking to do but I like what I’m seeing.Thank you so much for your help!
Greg
The topic ‘Relevanssi not functioning’ is closed to new replies.