admin管理员组文章数量:1277875
I've a small issue with the default search, I want to search cross different post_types and returning for example 5 items. In this moment if I search for the word: foo
and this word is in 10 wc products, 3 posts and 8 pages the search will return the the 5 product but it will not return any posts or pages, what I would like to have is that the search return:
5 products
3 posts
5 pages
is it possible somehow?
I've a small issue with the default search, I want to search cross different post_types and returning for example 5 items. In this moment if I search for the word: foo
and this word is in 10 wc products, 3 posts and 8 pages the search will return the the 5 product but it will not return any posts or pages, what I would like to have is that the search return:
5 products
3 posts
5 pages
is it possible somehow?
Share Improve this question edited Oct 22, 2021 at 12:48 Christine Cooper♦ 8,8977 gold badges60 silver badges93 bronze badges asked Oct 16, 2021 at 16:38 francesco.venicafrancesco.venica 1011 bronze badge1 Answer
Reset to default 0My first guess will be to run multiple custom queries on your search.php
template in order to change post_type
and posts_per_page
It could look like that
<?php
$s = get_search_query();
$args_array = [
{'s' =>$s,'post_type'=>'products','posts_per_page'=>5},
{'s' =>$s,'post_type'=>'posts','posts_per_page'=>3},
{'s' =>$s,'post_type'=>'pages','posts_per_page'=>5},
],
foreach( $args_array as $args ) {
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
// YOUR CODE HERE
endwhile;
wp_reset_postdata();
本文标签: search get minimum number of post for each post type
版权声明:本文标题:search: get minimum number of post for each post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741256709a2366818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论