Make wordpress search only in post title


I have a new website and I want to modify wordpress mystique theme 3.0 in order to search only in post title !!

How can i do itt ?


There are numbers of articles available in google if you have searched before you posted. wordress search only in post title

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 your functions.php

Need Your Help

Mockito: using a method in "thenReturn" to return a mock doesn't work

java unit-testing mocking mockito

I have encountered what I assume might be a bug with Mockito, but was wondering if anyone else can shed light as to why this test doesn't work.

How do I compile and run a C program in Sublime Text 2?

compiler-construction build compilation sublimetext2

I am completely new to programming. I have no idea how to compile & run a simple C program in Sublime Text 2.