admin管理员组

文章数量:1124388

I am trying to display the post count of some taxonomies. I have a custom template that I am showing some taxonomies on. I am using advanced custom fields to assign each repeater field to a taxonomy. How can I display the amount of post for each one?

I am trying to display the post count of some taxonomies. I have a custom template that I am showing some taxonomies on. I am using advanced custom fields to assign each repeater field to a taxonomy. How can I display the amount of post for each one?

Share Improve this question asked May 2, 2015 at 0:08 JediTricks007JediTricks007 8463 gold badges14 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use this code for getting number of posts in a taxonomy:

$args = array(
  'post_type'     => 'post',
  'post_status'   => 'publish',
  'posts_per_page' => -1,
  'tax_query' => array(
    array(
      'taxonomy' => 'your-taxonomy-name',
      'field'    => 'slug',
      'terms'    => 'some-slug',
    )
  )
);
$query = new WP_Query( $args );
echo $query->post_count;

本文标签: How to show amount of post in a taxonomy with advanced custom fields