Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

mysite.com/price/free

to have the headline

18 free resources

How can I achieve this?

share|improve this question

2 Answers 2

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

share|improve this answer

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;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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