Make Wordpress search in the message header only

Hiii,

I have a new site and I want to change the wordpress mystique 3.0 theme to search only in the message header !!

How can i do this?

+6
source share
1 answer

There are articles on google that you searched for before posting.
wordress search only in the message header

function __search_by_title_only( $search, &$wp_query ) { global $wpdb; if(empty($search)) { return $search; // skip processing - no search term in query } $q = $wp_query->query_vars; $n = !empty($q['exact']) ? '' : '%'; $search = $searchand = ''; foreach ((array)$q['search_terms'] as $term) { $term = esc_sql($wpdb->esc_like($term)); $search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')"; $searchand = ' AND '; } if (!empty($search)) { $search = " AND ({$search}) "; if (!is_user_logged_in()) $search .= " AND ($wpdb->posts.post_password = '') "; } return $search; } add_filter('posts_search', '__search_by_title_only', 500, 2); 

Add this code to functions.php

+32
source

Source: https://habr.com/ru/post/909467/


All Articles