0

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.com/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;

}
}

1 Answer 1

0

SOLUTION

  <?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 ;
    
    
    
    ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.