WordPress search only works with posts, not pages WordPress search only works with posts, not pages wordpress wordpress

WordPress search only works with posts, not pages


Add this code to your functions.php file.

function wpshock_search_filter( $query ) {    if ( $query->is_search ) {        $query->set( 'post_type', array('post','page') );    }    return $query;}add_filter('pre_get_posts','wpshock_search_filter');

http://wpth.net/limit-wordpress-search-results-to-specific-post-types


WP Search http://wpsear.ch/ has that ability.You can adjust what post types you want to show in results page.


In your search.php, find The Loop and insert this code just after it. You can recognize the Loop because it usually starts with:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

Code to be inserted:

if (is_search() && ($post->post_type=='page')) continue; 

So, your code should be like this:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?><?php if (is_search() && ($post->post_type=='page')) continue; ?>

Let me know if it worked.