0

I am new in php and trying to learning php. I have taxonomy called dealstore. I have added one store name "Amazon" and two categories name "coupons and electronics". Now, I want to post count which have Amazon store name and coupons category. I have tried


 <?php   $terms = get_the_terms( $post->ID , 'dealstore' );   
          foreach ( $terms as $term ) 
             {    
               echo $term->count; 
              } ?>

It counts All Post which have coupons category and electronics.

I have added another code

<?php
                    $custom_terms = get_the_terms( $post->ID , 'dealstore' );
                    foreach($custom_terms as $custom_term) {
                    wp_reset_query();
                    $args = array(
                    'post_type' => 'post',
                    'tax_query' => array(
                        'relation'=> 'AND',
                    
                    array(
                            'taxonomy' => 'dealstore',
                            'field' => 'slug',
                            'terms' => $custom_term->slug,
                            ),
                    array(
                            'taxonomy' => 'category',
                            'field' => 'slug',
                            'terms' => $custom_term->slug,
                            ),
                            
                        ),
                    );
                $query = new WP_Query( $args );
                 if ( $query->have_posts() ) :
                echo $query->post_count;
                ?>

can anyone help me to solve this ?

Thank you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.