admin管理员组文章数量:1300049
This topic has been ask in Stackexchange many times. But most of question unanswered or has incomplete answer. My custom post type "Product" and two different taxonomy "Sectors" and "Seasons". Now I want to display product count for Garden archive page ( garden is the term of sectors taxonomy) that have realtion with Winter ( winter is the term of seasons taxonomy). I did all my best during these 3 days but I can not solve this problem. Please help me. thanks for your attention. This is also a good source but can make it works
$sectors = get_queried_object();
$season = get_terms( array(
'taxonomy' => 'seasons',
'hide_empty' => true,
'fields' => '58', // winter term id
) );
foreach ($current_taxs as $current_tax) {
foreach ($seasons as $seasons) {
$args = array(
'post_type' => 'product',
'post_status'=>'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $current_tax,
'field' => 'slug',
'terms' => array( $current_tax ),
),
array(
'taxonomy' => 'season',
'field' => 'slug',
'terms' => array( $season ),
),
),
);
$query = new WP_Query( $args );
echo $query->post_count;
}
}
This topic has been ask in Stackexchange many times. But most of question unanswered or has incomplete answer. My custom post type "Product" and two different taxonomy "Sectors" and "Seasons". Now I want to display product count for Garden archive page ( garden is the term of sectors taxonomy) that have realtion with Winter ( winter is the term of seasons taxonomy). I did all my best during these 3 days but I can not solve this problem. Please help me. thanks for your attention. This is also a good source but can make it works https://wordpress.stackexchange/a/327150/196375
$sectors = get_queried_object();
$season = get_terms( array(
'taxonomy' => 'seasons',
'hide_empty' => true,
'fields' => '58', // winter term id
) );
foreach ($current_taxs as $current_tax) {
foreach ($seasons as $seasons) {
$args = array(
'post_type' => 'product',
'post_status'=>'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => $current_tax,
'field' => 'slug',
'terms' => array( $current_tax ),
),
array(
'taxonomy' => 'season',
'field' => 'slug',
'terms' => array( $season ),
),
),
);
$query = new WP_Query( $args );
echo $query->post_count;
}
}
Share
Improve this question
edited Mar 25, 2021 at 9:47
Teymur Abbasov
asked Mar 25, 2021 at 8:28
Teymur AbbasovTeymur Abbasov
618 bronze badges
1 Answer
Reset to default 0SOLUTION
<?php
$args = array(
'post_type' => 'product',
'post_status'=>'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sectors',
'field' => 'slug',
'terms' => 'garden',
),
array(
'taxonomy' => 'season',
'field' => 'slug',
'terms' => 'winter',
),
),
);
$query = new WP_Query( $args );
echo $query->post_count ;
?>
本文标签: wp querydisplay post count in archive page that have relation with another taxonomy term
版权声明:本文标题:wp query - display post count in archive page that have relation with another taxonomy term 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741655862a2390757.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论