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'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
add comment

2 Answers

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! –  pensky 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
add comment

I think this is what you want to do!

<?php
 $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. –  pensky material Jun 27 '13 at 12:19
add comment

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.