Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Filter the search by title for posts
- function filter_search_by_title($query){
- if($query->is_search() && $query->is_main_query()){
- $query->set('post_type', array('post'));
- $query->set('orderby', 'title');
- $query->set('order', 'ASC');
- }
- return $query;
- }
- add_action('pre_get_posts', 'filter_search_by_title');
- function highlight_search_results($content){
- if(is_search()){
- $search_string = get_query_var('s');
- $keys = explode(" ",$search_string);
- $content = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="highligh-search">'.$search_string.'</strong>', $content);
- }
- return $content;
- }
- add_filter('the_excerpt', 'highlight_search_results');
- add_filter('the_title', 'highlight_search_results');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement