WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using this code to display the last three posts of a custom taxonomy ('special') by a certain author:

<?php query_posts( array( 'taxo' => 'special', 'showposts' => 3, 'author' => 2 ) ); ?>

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>

<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

<?php endwhile; endif; ?><p>

Now I want WordPress to count also the total amount of posts this user made with this taxonomy and display the number, anyone knows how this would work?

Thanks in advance.

share|improve this question
up vote 1 down vote accepted
$args = array(
  'taxonomy' => 'special',
  'posts_per_page' => -1,
  'author' => 2

$author_category_posts = new WP_Query($args);

$count_of_posts_by_author = $author_category_posts->post_count;

You can fetch the number of posts made by that author in specific taxonomy.

share|improve this answer
that works for me, thanks! – penske material Jun 27 '13 at 13:47
If the answer works for you, then mark it as accepted so that the question won't remain unanswered. – Rohit Pande Jun 27 '13 at 13:54

I think this is what you want to do!

 $sql = "SELECT * FROM $wpdb->posts WHERE post_author = 2"; //where 2 is the author's id
$numposts = $wpdb->get_results($sql);   //returns an array of all post by the author
echo count($numposts);
share|improve this answer
thanks for your quick answer, but wouldn't that count all posts by the author? I want it to count only posts which A) were made by that author AND B) are in my 'special' taxonomy. – penske material Jun 27 '13 at 12:19

Your Answer


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.