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 badges1 Answer
Reset to default 1Setting 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
版权声明:本文标题:Show only "Pages" - not posts - on search page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741895351a2403542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论