WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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);
share|improve this answer
I think he wanted to just search post_content as opposed to all the other fields WP does by default. – TheDeadMedic Dec 11 '10 at 16:21
Yes I want to search only post_content, however it isn't doing it by default it's also checking titles. Are you sure it only checks the content by default? I'm sure it's not doing it in my page because my posts are 99% and just one word for content – Lisandro Dec 11 '10 at 21:23
What about the posts_search hook? – t31os Dec 12 '10 at 12:33
hai, easy la... find much better than my code.. Thank you.!! – user2219 Dec 30 '10 at 12:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.