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?

Read More

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

Related posts

Leave a Reply

2 comments

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

  2. 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.