How do I make search only search in post content?

I want to have two search bars, one which works normally and one that searchs only in the post content but I can’t even find the code of the search funtion to create the second.

Can I use a plugin to make my search function only search in post content? Thanks in advance

Related posts

Leave a Reply

1 comment

  1. This line in $wp_query might be of interest:

    $where = apply_filters_ref_array('posts_where', array( $where, &$this ) );
    

    You could probably use a filter to toss in an additional post_type = ‘post’. Something like:

    function search_where( $where, &$wp_query ) {
      if ( $wp_query->is_search ){
        where .= " AND post_type = 'post'";
      }
      return $where;
    }
    add_filter('posts_where', 'search_where', 10, 2);