1

When I have this URL:

http://localhost/website/?post_type=post&s=lorem

It shows me only the posts which have the word "lorem". Now I want to this with pages:

http://localhost/website/?post_type=page&s=lorem

I still get the posts. Any Idea? (With other custom post types like "portfolio" it works, too).

1 Answer 1

1

Setting the post type at pre_get_posts can solve this. You can set it like below-

function the_dramatist_search_only_page($query) {

    if ($query->is_search && !is_admin() ) {
        $query->set('post_type',array('page'));
    }

    return $query;
}

add_filter('pre_get_posts','the_dramatist_search_only_page');

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.