I have a custom post type called "RESOURCES" which I used to create a directory of resources on my website. This CPT has the taxonomy called "PRICES". There are three terms

  • free
  • free trial
  • premium

So, when someone's viewing my directory and they see in the sidebar "PRICES" with those options underneath, they could click on (for example) FREE and see 18 different free resources listed.

What I want is for that term page


to have the headline

18 free resources

How can I achieve this?


You can use WP_Query Methods and Properties to accomplish this. $wp_query->found_posts will return the amount of posts within the term while $wp_query->queried_object->name will return the name of the term currently displayed.

You can now just paste all these together to display

18 free resources

$taxcount = $wp_query->found_posts;
$taxname = $wp_query->queried_object->name;

printf(__( '%s %s resources' ), $taxcount, $taxname);

Modify as you wish to get the desired output and styling.

Note, this code should be added to your taxonomy template or archive template, depending on which template is been used to display the terms on


You can try using WP_Query like this to get all the posts in that taxonomy and count them.

$query = new WP_Query( array( 'PRICES' => 'FREE', 'posts_per_page' => -1 ) );
$count = $query->post_count;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.