tags:

views:

12

answers:

1

I need to list the authors and their emails alternatively. For example:

  • user1
  • email_of_user1
  • user2
  • email_of_user2

Also, the user1, user2 should be links to pages where posts are filtered by author. I can use wp_list_authors() function but I can't figure out how to do the alternate user, email thing.

A: 

Hi Gaurav,

This is exactly what you need. Displays a list of all the authors that have authored at least one post:

<?php
// Displays user name and email from users with at least one post
$blogusers = get_users_of_blog();
if ($blogusers) {
  foreach ($blogusers as $bloguser) {
    $args = array(
    'author' => $bloguser->user_id,
      'showposts' => 1,
      'caller_get_posts' => 1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      $user = get_userdata($bloguser->user_id);
      echo "<li>".$user->user_firstname."</li><li>".$user->user_email."</li>";
    }
  }
}
?>

The second IF ensures that the user has at least one post. If you want to display all the users (having posted something or not) remove these lines:

$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {

}

Hope this helps :)

Adapted code from here: http://wordpress.org/support/topic/274474?replies=2

XaviEsteve