I used to have a snippet that limits search results to titles only, but with recent updates it doesn't work any more. It will be great it of somebody can help here out, for me and others that looking for a solution to this. Thanks D
EDIT: That's the old code:
// Search by Title only!
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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331095a4622880.html
评论列表(0条)