Taxonomy Post Count for Custom Post Type
Author: Aleš Sýkora, 16. 5. 2019
Add this snippet to your functions.php or create your own plugin:
function my_taxonomy_posts_count_func( $atts ) {
extract(shortcode_atts(array(
'post_type' => 'post',
), $atts));
global $WP_Views;
$term = $WP_Views->get_current_taxonomy_term();
$args = array(
'post_type'=> $post_type,
'tax_query' => array(
array(
'taxonomy' =>$term->taxonomy,
'field' => 'id',
'terms' => $term->term_id,
)
),
'order' => 'ASC',
'posts_per_page' => -1,
'suppress_filters' =>0,
);
$posts = get_posts( $args );
$res=0;
if($posts)
{
$res = count($posts);
}
return $res;
}
add_shortcode( 'my-taxonomy-posts-count', 'my_taxonomy_posts_count_func' );
Add this shortcode to your view:
[my-taxonomy-posts-count post_type="jobs"]
And change the "jobs" to your CPT slug.