Tagged: Instant search, relevanssi
-
AuthorPosts
-
February 27, 2014 at 1:43 am #229857
I’m in the process of finishing up a development site before I move it to a live environment. I absolutely love the Enfold theme and have been able to, thus far, build a beautiful site using it (still have a lot left to finish unfortunately).
EDIT: I’m using the newest/latest version of Enfold, Version 2.5.2
Anyway, I installed Relevanssi and now my “instant search” results that Enfold serves up via Ajax do not match those results on the actual search results page. Within the Relevanssi settings I input specific page ID’s that I do not want returned in the search results. On the search results page, those pages I don’t want to appear in the search results don’t appear, which is great.
However, they are still appearing within the “Instant Search” results. This is very bad, because I have pages that should only be seen by customers of mine (like “Thank you for purchasing”, “Reduced Special Pricing Pages” and so on).
After searching the forums, I found a few posts detailing similar issues. I included the following code which I found on this post: https://kriesi.at/support/topic/enfold-code-update-for-2-2-to-use-relavanssi-plugin/ within my themes functions.php file (at the very bottom of it, beneath everything else within the file)
add_filter('avf_ajax_search_function', 'avia_init_relevanssi', 10, 4); function avia_init_relevanssi($function_name, $search_query, $search_parameters, $defaults) { $function_name = 'avia_relevanssi_search'; return $function_name; } function avia_relevanssi_search($search_query, $search_parameters, $defaults) { global $query; $tempquery = $query; $tempquery->query_vars = $search_parameters; relevanssi_do_query($tempquery); $posts = $tempquery->posts; return $posts; }
Unfortunately, that doesn’t work. I still am seeing pages that I specified within the Relevanssi settings as pages to not be returned in search results within the “Instant Search” results returned (but again, the pages I specified within the Relevanssi settings to not be returned in search results DO NOT appear on the actual search results page, which is correct…but they’re still appearing within the instant search results).
- This topic was modified 10 years, 9 months ago by crazyflx.
February 27, 2014 at 3:01 am #229870Hey crazyflx!
Add it to the top of your functions.php file just under:
if(isset($avia_config['use_child_theme_functions_only'])) return;
Regards,
DevinFebruary 27, 2014 at 3:14 am #229874Hello Devin!
Thanks so much for the quick reply, I really appreciate it. Unfortunately, it hasn’t yielded any different results. Here is what the beginning of my enfold functions.php file looks like (beyond what I’ve copy/pasted here, there are now zero changes…it’s exactly as it comes in a fresh download):
<?php global $avia_config; /* * if you run a child theme and dont want to load the default functions.php file * set the global var bellow in you childthemes function.php to true: * * example: global $avia_config; $avia_config['use_child_theme_functions_only'] = true; * The default functions.php file will then no longer be loaded. You need to make sure then * to include framework and functions that you want to use by yourself. * * This is only recommended for advanced users */ if(isset($avia_config['use_child_theme_functions_only'])) return; /* adding filter for instant search to return relevanssi filtered pages/posts */ add_filter('avf_ajax_search_function', 'avia_init_relevanssi', 10, 4); function avia_init_relevanssi($function_name, $search_query, $search_parameters, $defaults) { $function_name = 'avia_relevanssi_search'; return $function_name; } function avia_relevanssi_search($search_query, $search_parameters, $defaults) { global $query; $tempquery = $query; $tempquery->query_vars = $search_parameters; relevanssi_do_query($tempquery); $posts = $tempquery->posts; return $posts; } /*end relevanssi filter */
February 27, 2014 at 3:16 am #229875EDIT: forgot to make private
- This reply was modified 10 years, 9 months ago by crazyflx.
February 27, 2014 at 3:16 am #229878This reply has been marked as private.February 27, 2014 at 8:30 am #229954Hi!
You can try this code instead:
add_filter('avf_ajax_search_function', 'avia_init_relevanssi', 10, 4); function avia_init_relevanssi($function_name, $search_query, $search_parameters, $defaults) { $function_name = 'avia_relevanssi_search'; return $function_name; } function avia_relevanssi_search($search_query, $search_parameters, $defaults) { $tempquery = new WP_Query(); $tempquery->query_vars = $search_parameters; relevanssi_do_query($tempquery); $posts = $tempquery->posts; return $posts; }
It will make sure that a new query object will be used and the main query won’t affect the search query. If it doesn’t work please contact the plugin author for help because maybe it’s a limitation of the relevanssi_do_query() function and you can’t use it to exclude pages from the search query: http://www.relevanssi.com/knowledge-base/relevanssi_do_query/ . In this case some custom development might be required.
Best regards,
PeterFebruary 28, 2014 at 8:31 pm #230759Hello Dude,
Thanks very much for your help, I appreciate it. Unfortunately, that did not work either. It yields the same results as the previously entered code.
My entered page ID’s (as entered within the Relevanssi settings) that should be excluded from search results are successfully excluded from the search results on the actual WP search results page. They are still being returned in the “instant search” results by enfold though.
Thanks again for the help…do you think you could point me in the right direction with what I should be asking the folks over at Relevanssi?
March 1, 2014 at 10:06 am #231003Hey!
During my tests the relevanssi_do_query() function always returned the same results for the ajax search and the standard search but I didn’t test the “exclude page” option. I’d ask if there’re any limitations of the relevanssi_do_query() function which may effect the search results and produce a different result. You can also ask how (and if) you can add the excluded page ids to the search query somehow – i.e. the post__not_in parameter should enable you to exclude some pages/posts but I’m not sure how you can retrieve the excluded entries list from Relevanssi, etc.
Regards,
PeterNovember 3, 2014 at 10:01 pm #345547Hi guys,
crazyflx, did you ever end up solving this? I’m having the same issue right now…
-
AuthorPosts
- The topic ‘Search Results Not Matching "Instant Search" Results After Installing Relevanssi’ is closed to new replies.