When I have this URL:


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


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

1 Answer 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() ) {

    return $query;


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.