<?php
if ($_GET['cat'] != '') {
$posts = query_posts($query_string . '&post_type=post'); // return only posts
} else {
$posts = query_posts($query_string . '&post_type=page'); // return only posts
}
?>
<input type="hidden" name="cat" value="<?php echo $category[0]->cat_ID; ?>" />
First off @mindshare thank you for posting the code.
I ran into the following, and wanted to posts the results and obstacles because I haven't been able to find a solution so far:
I hardcoded the "input type" value because I noticed that if you get a search not found result the value would dissapear out of the url.
Hardcoding this value keeps the focus, which I then use to return a "search not found" template file which includes the correct search form again.
I want to add multiple search forms in various places and have these search in specified areas such as categories. Using for example "in_category" with elseif statements works. However, now the main search takes over the integer from the url... :/ Still haven't figured out that part out.
So I want to figure out how to get the main search to search through all the posts adn give a specified search results page regardless of the value in the url.
Using the '<?php echo $category[0]->cat_ID; ?>' could result in a lot less work, but the url integer would also have to be passed on a "no search result found." Maybe a query_posts and/or in combination with an if statement in the search result template would be an option...(?)