Month: March 2018

How to get count of posts in a particular category?

You can get get count of posts in a particular category by using below code. Before use please replace “CUSTOM_POST_TYPE” and “CUSTOM_TAXONOMY” with your post type and taxonomy.

$the_query = new WP_Query( array(
    'post_type' => 'CUSTOM_POST_TYPE',
    'tax_query' => array(
        array(
            'taxonomy' => 'CUSTOM_TAXONOMY',
            'field' => 'id',
            'terms' => TERM_ID
        )
    )
) );
$count = $the_query->found_posts;

Have any doubt please comment here.