Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created August 15, 2012 17:50
Show Gist options
  • Select an option

  • Save wpsmith/3361923 to your computer and use it in GitHub Desktop.

Select an option

Save wpsmith/3361923 to your computer and use it in GitHub Desktop.
Basic Use of WP_User_Query
<?php
// prepare arguments
$args = array(
'orderby' => 'display_name', // Order by display name
'exclude' => array( 2, 5, ), // Remove the two main admins
);
// Create the WP_User_Query object
$author_query = new WP_User_Query( $args );
// Get the results
$authors = $author_query->get_results();
// Output results
foreach( $authors as $author ):
$pattern = '<%1$s class="%2$s">%3$s</%1$s>';
echo '<div class="author author-' . $author->ID . ' author-' . $author->user_nicename . '">';
printf( $pattern, 'div', 'author-gravatar', '<a href="' . get_author_posts_url( $author->ID ) . '">' . get_avatar( $author->user_email, 96, null, $author->display_name ) . '</a>' );
printf( $pattern, 'h3', 'author-name', '<a href="' . get_author_posts_url( $author->ID ) . '">' . $author->display_name . '</a>' );
printf( $pattern, 'div', 'author-description', get_the_author_meta( 'user_description', $author->ID ) );
echo '</div>';
endforeach;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment