Sometimes you want to change the way wordpress search works, for example you want it to force to search pages only or just posts. The code for that would be something like this
//Search only pages
function is_type_page() {
global $post;
if ($post->post_type == 'page') {
return true;
} else {
return false;
}}
//Search only posts
function is_type_post() {
global $post;
if ($post->post_type == 'post') {
return true;
} else {
return false;
}}
Then in the search page, i.e search.php just use this code
while ( have_posts() ) : the_post(); if (is_type_post()) continue;
Above code will restrict search to the pages only. Similarly you can restrict pages to be excluded from search with the following code
while ( have_posts() ) : the_post(); if (is_type_page()) continue;
Hope that helps




