Time for some live-tooting of debugging a problem I’m having in a client’s WordPress install.
The Problem:
When updating the product gallery for a WooCommerce product, the search box doesn’t seem to filter anything at all.
Background:
- The site is old, but has received many updates over the years.
- WordPress + WooCommerce + some other plugins.
- I like code, so no site builder.
I did some debugging the other day and narrowed the problem down to the posts_search filter in the WP Query class. Before running the filter the SQL to filter by the search parameter is there, but after running the filter it is not.
Doing a print_r() on the global $wp_filter it seems like nothing is hooked onto the posts_search filter.
At this point I think I should fire up a an actual debugger and follow along as the code is executed.
So, now I need to learn to get XDebug running in a WordPress site hosted locally with Laravel Valet.
Half an hour to get Xdebug working and I already had it installed!
It seems that while I had Xdebug installed, I did not have the xdebug.ini file I needed. Now that’s fixed, let’s start stepping through code.
And solved.
It turns out that in a custom plugin I wrote, I was exiting early from a function that I had hooked onto posts_search - a good thing! But I didn’t return the unchanged SQL, I just returned null, oops!
Changing:
return;
to
return $sql;
fixes the problem.
Xdebug saves the day!