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

What I want: http://i.imgur.com/jH6Dj.png (sorry for linking out, I am a new user here so can't post an image inline)

How does one list posts by an author within a category, with a count for each category, on the author archive page?

share|improve this question
up vote 0 down vote accepted

Not the most efficient way but it works, put this in your theme's functions.php

function author_post_breakdown($author_id){
    //get all post of this author
    $n = get_posts(array(
        'author' => $author_id,
        'posts_per_page' => -1,
        'fields' => 'ids'
    $cats= array();
    //loop over all post of this author and get the categories for each post
    foreach((array)$n as $id){
        $cs = wp_get_object_terms($id, 'category');
        //loop over each category of the post and add the counter
        foreach($cs as $c){
            if (isset($cats[$c->slug])){
                $cats[$c->slug]['count'] = $cats[$c->slug]['count'] + 1;
                $cats[$c->slug]['count'] = 0;
                $cats[$c->slug]['name'] = $c->name;
    foreach($cats as $sl => $arr)
        $retVal = '<li><a href="'.get_term_link($slug, 'category').'">'.$arr['name'].'('.$arr['count'].')</a></li>'; 

    return $retVal;

and in your author.php add this:

$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $_GET['author_name']) : get_userdata($_GET['author']);
echo '<ul>'.author_post_breakdown($curauth->ID).'</ul>';
share|improve this answer
Thanks! When I added the function to the functions.php file, the site still ran swell. However, when I added this to the author.php file, everything after wherever it was inserted wouldn't load on to the page in a browser (note the page would still load though, no 500 error or anything): <?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $_GET['author_name']) : get_userdata($_GET['author']); echo '<ul>'.author_post_breakdown($curauth->ID).'</ul>'; ?> Thanks again - seriously - and apologies if it's my user error with the added <?php ?> text somehow (is it?) – GlennIsaac Mar 1 '12 at 23:43
create a pastebin of your authors.php file – Bainternet Mar 1 '12 at 23:53

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.