Php 按分类ID显示自定义分类后计数

Php 按分类ID显示自定义分类后计数,php,wordpress,taxonomy,custom-taxonomy,Php,Wordpress,Taxonomy,Custom Taxonomy,我正在寻找一种通过ID显示每个自定义分类法中的帖子数量的方法,我想在侧栏导航中显示帖子数量,它不是任何查询的一方,因此我有每个自定义分类法ID,但不确定如何从中获取帖子数。我看wordpress有这个功能 <?php wp_count_terms( $taxonomy, $args ); ?> 尽管我需要自定义分类法中每个类别的帖子数量,而不是整个自定义分类法中每个类别的帖子数量。我找到了解决方案,以防有人在寻找它 <?php $args = array( '

我正在寻找一种通过ID显示每个自定义分类法中的帖子数量的方法,我想在侧栏导航中显示帖子数量,它不是任何查询的一方,因此我有每个自定义分类法ID,但不确定如何从中获取帖子数。我看wordpress有这个功能

 <?php wp_count_terms( $taxonomy, $args ); ?>


尽管我需要自定义分类法中每个类别的帖子数量,而不是整个自定义分类法中每个类别的帖子数量。

我找到了解决方案,以防有人在寻找它

    <?php 
$args = array(
'post_type' => 'guides',
'post_status' => 'published',
'taxonomy-name' => 'category slug of taxonomy',
'numberposts' => -1,
    );
    echo $num = count( get_posts( $args ) );

?>

我找到了解决方案,以防有人找它

    <?php 
$args = array(
'post_type' => 'guides',
'post_status' => 'published',
'taxonomy-name' => 'category slug of taxonomy',
'numberposts' => -1,
    );
    echo $num = count( get_posts( $args ) );

?>

我找到了解决方案,以防有人找它

    <?php 
$args = array(
'post_type' => 'guides',
'post_status' => 'published',
'taxonomy-name' => 'category slug of taxonomy',
'numberposts' => -1,
    );
    echo $num = count( get_posts( $args ) );

?>

我找到了解决方案,以防有人找它

    <?php 
$args = array(
'post_type' => 'guides',
'post_status' => 'published',
'taxonomy-name' => 'category slug of taxonomy',
'numberposts' => -1,
    );
    echo $num = count( get_posts( $args ) );

?>