Are you using WordPress 3.1+? There’s a nice get_users()
function that’ll do the trick! However, you will need a little magic to boot:
add_action( 'pre_user_query', 'wpse_11832_pre_user_query' );
/**
* Adds "post_count" to the SELECT clause. Without this, the "post_count"
* property for users will be undefined.
*
* @param object $wp_user_query
*/
function wpse_11832_pre_user_query( $wp_user_query ) {
if ( $wp_user_query->query_vars['orderby'] == 'post_count' )
$wp_user_query->query_fields .= ', post_count';
}
And example usage:
<?php foreach ( get_users( 'order=DESC&orderby=post_count&number=5' ) as $user ) : ?>
<?php echo $user->display_name; ?> (<?php echo $user->post_count; ?> Posts)
<?php endforeach; ?>
Important: You must order by post_count
, otherwise it will be undefined.