试试这个。这是一个过滤搜索查询并用其“哑”等价物替换任何智能引号的函数。
<?php
/**
* Filter smart quotes out of a search query.
* Replace them with "dumb" quotes.
*
* @param WP_Query $query Instance of WP_Query.
*/
function filter_search_smart_quotes( $query ) {
if ( $query->is_search() ) {
$search = $query->get( \'s\' );
$smart_quotes = array(
chr( 145 ),
chr( 146 ),
chr( 147 ),
chr( 148 ),
chr( 151 ),
);
$dumb_quotes = array(
"\'",
"\'",
\'"\',
\'"\',
\'-\',
);
$search = str_replace( $smart_quotes, $dumb_quotes, $search );
$query->set( \'s\', $search );
}
}
add_action( \'pre_get_posts\', \'filter_search_smart_quotes\' );