Available since: 1.0
searchwp_terms
View Parameters »Allows you to modify a search query after it was submitted but before SearchWP sanitizes it and subsequently performs the search.
Example: If you want to correct a common spelling mistake, add the following to your active theme’s functions.php
:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// if your visitors commonly misspell "soccer" as "socer" you can fix that for them | |
function my_parse_searchwp_terms( $query, $engine ) { | |
if( false !== strpos( strtolower( $query ), 'socer' ) ) { | |
$query = str_replace( 'socer', 'soccer', strtolower( $query ) ); | |
} | |
return $query; | |
} | |
add_filter( 'searchwp_terms', 'my_parse_searchwp_terms', 10, 2 ); |
Parameters
Parameter | Type | Description |
---|---|---|
$query |
Array|String |
The search query as it was submitted |
$engine |
String |
The search engine being used for this search |