Product Search no longer working
-
When I do a product search, I no longer have results.
I disabled all plugins and then it worked. Then I enabled Relevanssi and it stopped working. Can you please check what is going on?The page I need help with: [log in to see the link]
-
I’ve found a fix to the problem, and it’s surprisingly simple. Just add this to your theme
functions.php
:remove_filter( 'posts_request', 'relevanssi_prevent_default_request' );
I’m still trying to figure out what exactly has happened, and how to best implement this change in Relevanssi, but the next version of Relevanssi will include this fix.
If this doesn’t fix the problem for someone, please let me know.
Further detail, in case someone can offer some suggestions:
The key here is
wc_get_loop_prop( 'total' )
in thearchive-product.php
template from WooCommerce. With Relevanssi enabled andrelevanssi_prevent_default_request
active, this returns 0, because Relevanssi prevents the default request and thus no posts are found, even though Relevanssi has found posts. Withrelevanssi_prevent_default_request
disabled,wc_get_loop_prop( 'total' )
returns a non-zero value and WooCommerce is happy displaying the Relevanssi results.I’ve confirmed this has changed between WooCommerce versions 4.3.3 and 4.4.0. For some reason
wc_get_loop_prop( 'total' )
doesn’t return 0 with WC 4.3.3. Still digging into this…Did you test with WC 4.4.1?
Yes, I’m working with 4.4.1. No difference between 4.4.0 and 4.4.1.
Seems to me the key function here is unchanged between 4.3 and 4.4, so this is all quite bizarre, I don’t know why the two versions behave in different ways.
Maybe open a github issue with WooCommerce?
Found it! The reason for this is the new
adjust_posts_count()
function, introduced in WooCommerce 4.4.0. This function causes WooCommerce to set up the post loop before Relevanssi has done the search, causing all these problems. In previous versions, the post loop was set up only after Relevanssi had done it’s job, which made everything work smooth.Now, with the fix above, the search still works, but there are some problems. At least Storefront displays the wrong number of results, because it uses the number generated by
adjust_posts_count()
before Relevanssi. I’m not sure how to fix this so yes, a GitHub issue with WooCommerce is the way to go.Excellent investigation Mikko! These kind of changes are always tough. Hope you will find a solution soon.
Writing the issue was the key, it lead me to a better solution. Adding this to the theme
functions.php
should also fix the problem:add_action( 'woocommerce_before_shop_loop', 'wc_reset_loop' );
This is a better solution than
remove_filter( 'posts_request', 'relevanssi_prevent_default_request' );
because with this better solution, the found post counts on the results pages should be correct.
I still posted the issue, I suppose it’s good for the WooCommerce folks to know about the side effects of the changes in the plugin: https://github.com/woocommerce/woocommerce/issues/27420
Thanks to all who brought this issue to my attention.
I gave your github issue a thumbs up!
@msaari I have archived your reply and flagged your account for moderation.
While I know you have the best of intentions, it’s forum policy that you not ask users for admin or server access. Users on the forums aren’t your customers, they’re your open source collaborators, and requesting that kind of access can put you and them at high risk.
If they are paying customers (such as people who bought a premium service/product from you) then by all means, direct them to your official customer support system. But in all other cases, you need to help them here on the forums.
Thankfully are other ways to get information you need:
- Ask the user to install the Health Check plugin and get the data that way.
- Ask for a link to the https://pastebin.com/ or https://gist.github.com log of the user’s web server error log.
- Ask the user to create and post a link to their
phpinfo();
output. - Walk the user through enabling WP_DEBUG and how to log that output to a file and how to share that file.
- Walk the user through basic troubleshooting steps such and disabling all other plugins, clear their cache and cookies and try again (the Health Check plugin can do this without impacting any site vistors).
- Ask the user for the step-by-step directions on how they can reproduce the problem.
You get the idea.
We know volunteer support is not easy, and this guideline can feel needlessly restrictive. It’s actually there to protect you as much as end users. Should their site be hacked or have any issues after you accessed it, you could be held legally liable for damages. In addition, it’s difficult for end users to know the difference between helpful developers and people with malicious intentions. Because of that, we rely on plugin developers and long-standing volunteers (like you) to help us and uphold this particular guideline.
When you help users here and in public, you also help the next person with the same problem. They’ll be able to read the debugging and solution and educate themselves. That’s how we get the next generation of developers.
I am now closing this topic as it became a pile on topic and I have archived the replies.
If anyone needs support then per the forum guidelines please start your own topic.
You can do so here.
https://www.ads-software.com/support/plugin/relevanssi/#new-post
- The topic ‘Product Search no longer working’ is closed to new replies.