Searching Only Blog Posts From a WordPress Site’s Main Posts Page?

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?

EDIT

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" />
</form>

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?)

2 Answers
2

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" />

Leave a Comment