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.

$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.

  • If the answer works for you, then mark it as accepted so that the question won't remain unanswered. 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);
  • 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. Jun 27 '13 at 12:19

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.