Optimize WP search query term


I made the following filter to remove s from terms shirts or hoodies, however I don’t think it’s the way it should be. Any ideas if I can make it in a more proper way?

 //we check if the search term has enough length & contains "shirts" or "hoodies" then remove "s" from the end of the words.
 if (isset($_GET["s"]) 
     and substr(strtolower($_GET["s"]),-6)=='shirts' 
     and strlen($_GET["s"])>5) {
else if (isset($_GET["s"])
     and substr(strtolower($_GET["s"]),-7)=='hoodies' 
     and strlen($_GET["s"])>6) {
    return $query;

Also, is there any way to include a clause in the above function when someone type tshirt to show results for t-shirt and same for tshirts to show results for t-shirt?

Basically my idea is the following:
All of these terms (t-shirts,shirt,shirts,tshirt,tshirts) to display results for term t-shirt.
And hoodies to simply display results for hoodie in singular form.
Thank you!

Korla 4 months 0 Answers 17 views 0

Leave an answer