0

I have a CPT called 'Athlete' and a Taxonomy called 'School'.

Two sample terms have been added called 'term1' and 'term2'.

When a user views the archive for any of the 2 terms (taxonomy-school.php), I need to be able to echo the current post count of posts from within the Athlete CPT that contain the currently viewed taxonomy term.

So basically something like this:

<?php echo count_posts ('athlete', 'school', $currentTaxTerm); ?>

Is this possible, appreciate any pointers?

1

In your taxonomy archive template, just add the following:

At the top: global $wp_query;

Then to get the post count for the entire term:

echo $wp_query->found_posts

This will display all posts in the query, which in a taxonomy template will be all posts attached to a term.

WP Query Codex

-2

When you get into the loop on the archive page, you can do this :

if(have_posts()) {
  echo found_posts() . " total posts";
}
while(have_posts()) {

  // display each post

}
  • found_posts() doesn't seem to be in the list of available WP Query Methods and I couldn't get this to work on a taxonomy archive template. – Howdy_McGee Nov 11 '14 at 21:45

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.