[ACCEPTED]-WordPress search only works with posts, not pages-themes

Accepted answer
Score: 39

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

0

Score: 0

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

Score: 0

In your search.php, find The Loop and insert 4 this code just after it. You can recognize 3 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 2 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 1 it worked.

More Related questions