Originally found at : https://elwpin.com/2018/05/04/wordpress-search-redirect-plural-search-terms-to-singular-ones/

add to functions.php

//first filter for removing plural suffix from the end of given term.
//Even if the word is not in plural, it just ends with "s", you don't lose anything.
add_filter('posts_where',function($query){
//we check if the search term has enough length and contains "s" at the end.
if (isset($_GET["s"])
and substr(strtolower($_GET["s"]),-1)=='s'
and strlen($_GET["s"])>3) {
$query=str_replace($_GET["s"],
substr($_GET["s"],0,-1),
$query);
}
return $query;
});
//second filter is for making found results with the same order.
add_filter('posts_orderby', function($orderby){
$orderby=str_replace($_GET["s"],
substr($_GET["s"],0,-1),
$orderby);
return $orderby;
});

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.