WordPress.org

Ready to get started?Download WordPress

Forums

How do I limit my search on post's title only? (3 posts)

  1. jessicakoh
    Member
    Posted 6 years ago #

    How do I limit my search on post's title only?

    Below are my codes.

    <h3><?php _e('Search','k2_domain'); ?></h3>
    <div id="search" class="widget widget_search">
    <form id="searchform" method="get" action="http://www.mydomain.com">
    <div>
    <input type="text" name="s" id="s" size="15" />
    <input type="submit" value="Search" />
    </div></form>
    </div>
    <br class="clear" />
  2. anschorr
    Member
    Posted 6 years ago #

    bumping this as i need it too.
    any ideas?

  3. sangeethabhatta
    Member
    Posted 6 years ago #

    1.open wp-includes/query.php

    2.search for

    $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}'))";

    3.remove the OR part.

    to be specific

    $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}'))";

    4.if u want exact title search, change it to

    $search .= "{$searchand}((post_title='{$term}'))";

    LOL
    -sangeetha :)

Topic Closed

This topic has been closed to new replies.

About this Topic