fix wrong search results on special chars
This commit is contained in:
parent
5e216478a3
commit
dae32307ff
1 changed files with 9 additions and 27 deletions
|
|
@ -431,32 +431,14 @@ add_action( 'widgets_init', 'kit_widgets_init' );
|
||||||
|
|
||||||
# Highlight query in search results
|
# Highlight query in search results
|
||||||
|
|
||||||
function highlight_search_term_placeholders() {
|
function highlight_results($text) {
|
||||||
static $iter = 0;
|
if (is_search() && !is_admin()) {
|
||||||
$ret = "|##{$iter}##|";
|
$sr = get_query_var('s');
|
||||||
$iter++;
|
$keys = explode(' ', $sr);
|
||||||
return $ret;
|
$keys = array_filter($keys);
|
||||||
}
|
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="tx-indexedsearch-redMarkup">\0</strong>', $text);
|
||||||
function highlight_search_term_cb() {
|
|
||||||
static $iter = 0;
|
|
||||||
$ret = "##{$iter}##";
|
|
||||||
$iter++;
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
function highlight_search_term($text){
|
|
||||||
if(is_search() && !is_admin()){
|
|
||||||
$keys = implode('|', explode(' ', get_search_query()));
|
|
||||||
$pattern = '/<[^>].*?>/i';
|
|
||||||
preg_match_all($pattern,$text,$matches);
|
|
||||||
$placeholders = array();
|
|
||||||
foreach ($matches[0] as $v) {
|
|
||||||
$placeholders[] = highlight_search_term_placeholders();
|
|
||||||
}
|
|
||||||
$text = preg_replace_callback($pattern,'highlight_search_term_cb',$text);
|
|
||||||
$pattern2 = '/(' . $keys .')/iu';
|
|
||||||
$text = preg_replace($pattern2, ' <strong class="tx-indexedsearch-redMarkup">\1</strong> ', $text);
|
|
||||||
$text = preg_replace($placeholders,$matches[0],$text);
|
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
add_filter('the_excerpt', 'highlight_search_term');
|
|
||||||
|
add_filter('the_excerpt', 'highlight_results');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue