admin管理员组文章数量:1279051
Assuming I have these custom post types:
- Product
- Video
- Article
And for Product (WooCommerce Product), we have many Categories, one of which is called "Parts".
I have this situation where I need to sort my search query using the following rule:
- Product (that is not Parts), then
- Product (Parts), then
- Video, then
- Article
That means if I search a keyword, say "engine", Products should come out first (with main products coming out before parts). Then Video and Article should come later.
Is it possible to capture such a use case?
I've solved the issue with "Sort By Post Type", referring to this post: Sort search results by post type
What puzzles me is, how can we sort by Post Type and then by Taxonomy, but only in the case if the post_type is Product.
Any idea?
Assuming I have these custom post types:
- Product
- Video
- Article
And for Product (WooCommerce Product), we have many Categories, one of which is called "Parts".
I have this situation where I need to sort my search query using the following rule:
- Product (that is not Parts), then
- Product (Parts), then
- Video, then
- Article
That means if I search a keyword, say "engine", Products should come out first (with main products coming out before parts). Then Video and Article should come later.
Is it possible to capture such a use case?
I've solved the issue with "Sort By Post Type", referring to this post: Sort search results by post type
What puzzles me is, how can we sort by Post Type and then by Taxonomy, but only in the case if the post_type is Product.
Any idea?
Share Improve this question asked Oct 12, 2021 at 12:36 wooncherkwooncherk 1113 bronze badges1 Answer
Reset to default 1yes, offcourse it is possible, I had made two websites for selling car pieces myself and that is very possible. anything is possible.
you can create your own search results with the file search.php
here are two ways of getting products info:
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'meta_key' => '_last_viewed',
'orderby' => 'meta_value',
'order' => 'DESC'
);
query_posts( $args );
if( have_posts() ) :
while( have_posts() ) :
the_post();
echo the_title();
endwhile;
endif;
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'desc',
);
query_posts( $args );
if( have_posts() ) :
while( have_posts() ) :
the_post();
echo the_title();
endwhile;
endif;
I hope this can give an idea on how to get your goal
to have exactly what you need only having more specifics.
in this two examples, can be searched the first and display it, than do another search with the requiremens needed and display the second results and so foward. if we dont want something to be display we make ways to filter the info and not displaying it.
本文标签: Order By Post Type ThenBy Taxonomy
版权声明:本文标题:Order By Post Type ThenBy Taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741271429a2369376.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论