On my CMS-style setup, I have the standard search box which searches everything.

However, on my blog page, I would like to also have another search box which searches just the blog... is this possible, and how would I go about it?


I used this code within a text widget which goes on my blog page:

<form  id='searchform' method='get'>
<input style='margin-top:5px;' type='text' name='s' id='s' placeholder='Search (blog only)'>
<input type='hidden' name='post_type' value='post' />

This has the advantage that the results page is styled like the blog, and not the standard search page. (though I don't know how to indicate that the page is showing search results.. how to show this?)

  • Would it work for the blog search box to be limited to searching posts only? – Travis Northcutt Sep 10 '10 at 15:39
  • Hi @cannyboy: No problem, thanks for hanging out here and asking good questions! – MikeSchinkel Sep 11 '10 at 23:02

Hi @cannyboy:

There's a plugin called Search Unleashed that gives lots of different functionality. One of my clients was using it and I was impressed with the control it gave. Not 100% sure it will give you what you need but it's worth checking out.

If your blog only has post_types of "post" and you don't use them for the rest of the site you could use @TerryMatula's suggestion but with $post_type => 'post' instead, i.e.:

<input type="hidden" name="post_type" value="post" />

  • Thanks, I ended up putting this code in the text widget on my blog page (see my updated question) – cannyboy Sep 11 '10 at 15:50

If the Blog is in its own category, you could copy the searchform.php code, and then add this:

<input type="hidden" name="cat" value="{your category id}" />

of course, replacing {your category id} with the actual ID number. You could either put the entire form code into a widget, or directly into your template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.