admin管理员组文章数量:1418113
I have a requirement where i need to restrict wordpress search to pages listing only and disable products listing . In other words i wanted to replace post type in the search url from 'products' to 'page'. Any possible solution ?
I have a requirement where i need to restrict wordpress search to pages listing only and disable products listing . In other words i wanted to replace post type in the search url from 'products' to 'page'. Any possible solution ?
Share Improve this question asked Aug 2, 2019 at 5:33 Syam SuthanSyam Suthan 111 bronze badge 1- It was solved as i uninstalled woo commerce plugin. – Syam Suthan Commented Aug 2, 2019 at 5:56
1 Answer
Reset to default 1There are better ways, but one easy way to achieve this if you wanted to customise the search results is to edit the search.php template and make the WP_Query a custom one:
<?php
$args = array(
's' => get_search_query(),
'post_type' => array('page'),
);
$search_query = new WP_Query($args);
if ( have_posts() ) :
while ( $search_query->have_posts() ) : $search_query->the_post();
// do stuff here
endwhile;
wp_reset_query();
endif;
?>
本文标签: post typeHow to restrict wordpress search to pages and disable products listing search
版权声明:本文标题:post type - How to restrict wordpress search to pages and disable products listing search? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745276187a2651201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论