获取当前分类法帖子计数


Get current taxonomy post count

是否有方法获得当前分类法(类别或标签)帖子计数?我所拥有的代码仅适用于类别

<?php 
    $cat = get_query_var( 'cat' );
    $categories = get_categories( 'include='.$cat );
    if ( $categories ) { 
        foreach( $categories as $category ) { 
            echo '' . $category->count;
        }
    }
?>

我想你可以这样做:

// Set the name of your Taxonomy or get it as you're currently doing
// It can be category, tag or custom taxonomy name
$taxonomy = "your_taxonomy"; 
$total_count = 0;
// Get all the terms in your Taxonomy and add the count for each term
foreach ( get_terms( $taxonomy ) as $term ) {
    $total_count += (int) $term->count;
}
echo $total_count;

这将为您提供在分类法your_taxonomy中分配任何术语的所有帖子的计数,我理解这是您想要的…