Change searched term

So I’m trying to set up a search form in which which the term actually searched for would be different than what the user entered in. Specifically, I needed any dashes in the searched terms removed. For example, let’s say the user enters “7-18”. What the search actually needs to query is “718”. I’m thinking


might be the way to go but I’m not sure how to go about writing it. Something like

function alter_query($query) {
$unedit = the_search_query();
$edited = str_replace(“-“,””,$unedit);
the_search_query() = $edited;

Takes the entered value, removes the dashes, and uses it at the new search query in the search form. It doesn’t work though, and I don’t know if it’s because you can’t set the_search_query() with php, because it forms a loop, or if there is some other reason. Thoughts?

Read more here:: Change searched term

Leave a Reply

Your email address will not be published. Required fields are marked *