admin管理员组

文章数量:1312673

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).

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).

Share Improve this question asked Feb 14, 2017 at 16:18 herrfischerherrfischer 2274 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: Show only quotPagesquotnot postson search page