您可以使用get_search_query
滤器
function mySearchFunction($search_term){
$search_term = substr($search_term, 0, -1);
return $search_term;
}
add_filter(\'get_search_query\',\'mySearchFunction\');
EDIT
筛选查询结果的操作:
function mySearchFilterFunction($query) {
if ( !is_admin() && $query->is_main_query() && $query->is_search) {
$search_term = $query->get(\'s\');
$query->set(\'s\', substr($search_term, 0, -1));
}
}
add_action( \'pre_get_posts\', \'mySearchFilterFunction\');
get_search_query
不需要筛选器,因为它使用
get_query_var( \'s\' )
由我们的
pre_get_posts
行动