Support

Account

Home Forums General Issues Show number of posts with specific value within a category Reply To: Show number of posts with specific value within a category

  • Sorry just re-read your question. You need to get the number of posts with a difficulty of Easy, Average & Difficult for each term right?

    You’ll need a custom wp_query with a tax_query and a meta_query.. Something like the below will get you the post count for Easy Chocolate Deserts..

    
    $args = array(
    	'post_type'  => 'recipes',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'desserts',
    			'field'    => 'slug',
    			'terms'    => 'chocolate',
    		),
    	),
    	'meta_query' => array(
    		array(
    			'key'     => 'difficulty',
    			'value'   => 'Easy',
    			'compare' => 'IN',
    		),
    	),
    );
    $easy_choc_query = new WP_Query( $args );
    
    echo $easy_choc_query->found_posts;
    

    More info from the Codex

    To make it more dynamic we’d need to see your html structure. You’d possibly need to put something like the above inside the get_terms foreach loop, swapping out ‘chocolate’ and ‘easy’ for variables that changed with each iteration.