How to display an archive with multiple authors

This would make sense as an inclusion for the Co-Authors Plus plugin but you can’t always depend on plugin developers to anticipate all our needs. Sometimes we just have to build for ourselves! 🙂

Screenshot showing Co-Authors Plus Plugin for WordPress
(source: mikeschinkel.com)

Co-Authors Stored as Terms of the Taxonomy 'author'

Turns out what you want to do is not too hard. I’ll praise the plugin developers for using what I consider best practices; they created a taxonomy called 'author' and for the names of the terms they used the author’s user_login field.

Use get_terms() to get a list of Co-Authors

So it’s easy to get a list of authors just by calling the WordPress core function get_terms() passing it the taxonomy 'author' and specifying that you only need the term 'name' field.

Direct SQL required for a List of Author IDs

Unfortunately thumbs down to WordPress core for providing no way to get a list of author IDs based of a list of user_login values other than with direct SQL.

Our get_coauthor_list() function

Taken together we can create our simple get_coauthor_list() function to return a list of author IDs for all the available Co-Authors. Here’s the code (you can add this to the bottom of your theme template file, or better put in your theme’s functions.php file, or even better still get the Co-Authors Plus folks to add to their plugin):

function get_coauthor_list() {
  global $wpdb;
  $authors = implode("','",get_terms('author',array('fields'=>'names')));
  $sql = "SELECT ID " .
         "FROM {$wpdb->users} " . 
         "WHERE user_login IN ('{$authors}') " .  
         "ORDER BY display_name";
  return $wpdb->get_col($sql);
}

Using get_coauthor_list() in your Theme

From there it’s pretty simple to just add to your theme template file. I’ve modified your code slightly to use the get_coauthor_list() function and to follow some best practices such as using the get_author_posts_url() function found in WordPress core:

<h2>Archives by Author:</h2>
<?php
  $authors = get_coauthor_list();
  if($authors)
    foreach($authors as $author_id):
    ?>
    <div class="author" id="author-<?php the_author_meta('user_login', $author_id); ?>">
      <h3>
        <a href="https://wordpress.stackexchange.com/questions/5871/<?php echo get_author_posts_url($author_id); ?>">
          <?php the_author_meta('display_name', $author_id); ?>
        </a>
      </h3>
      <div class="description">
        <p>
          <?php if($author_description = get_the_author_meta('description',$author_id)): ?>
            <?php echo $author_description; ?>
          <?php else : ?>
            No description in the author's profile.
          <?php endif; ?>
        </p>
      </div>
    </div>
    <?php
    endforeach;
?>

And when it’s all said and done it looks like this:

Screenshot showing Author Archive for Co-Authors Plus Plugin for WordPress
(source: mikeschinkel.com)

P.S. Ironically to figure this out for you I had to install the plugin which then required me to debug (what turned out to be an insignificant) error message on plugin activation that resulted in my submitting this bug report; hopefully they will correct the bug in future releases.