[wp-hackers] Including only excerpt in search

Simon Blackbourn piemanek at gmail.com
Wed Apr 20 09:15:29 UTC 2011

i've adapted this from the codex[1], i haven't tested it so let me know if
it works.

add_filter( 'posts_where', 'my_search_where' );

function my_search_where( $where ) {
    if ( is_search() ) {
      $where = preg_replace(
         "(post_title LIKE $1) OR (post_excerpt LIKE $1)", $where );

    return $where;


you could also use the relevanssi plugin[2], which has an option for
searching excerpts (as well as a whole bunch of other stuff that massively
improves the search).


[1] http://codex.wordpress.org/Custom_Queries#Keyword_Search_in_Plugin_Table
[2] http://wordpress.org/extend/plugins/relevanssi/

More information about the wp-hackers mailing list