Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What I would like to do is have a list of users who have contributed at least one post.

I need to show the following:

[User photo] | [User Name] | [User post count]


[photo] Joe Bloggs(8)

I made a start and went down this route:

   $blogusers = get_users( 'orderby=post_count' );
      foreach ( $blogusers as $user ) {
      echo '<li>' . esc_html( $user->display_name ) . '</li>';

However, this seems to just return all users registered to the blog rather than those who have contributed so I'm certainly not doing it correctly.

I am new to wordpress and PHP so all help would be appreciated.

share|improve this question
Want something styled? Try this – Brad Dalton Aug 16 '14 at 12:24
Thanks Brad, I will have a look at that as well! – steakpi Aug 16 '14 at 13:12

2 Answers 2

up vote 4 down vote accepted

You need to set the who parameter in get_users

   $blogusers = get_users( 'orderby=post_count&who=authors' );
      foreach ( $blogusers as $user ) {
      echo '<li>' . esc_html( $user->display_name ) . '</li>';


Seems I was to fast answering. The code in your question and in my answer is the start to what you want to achieve.

I don't have time to code now, off to watch rugby, but here is the complete code used in the twenty fourteen to display authors and their post count. Hope this helps

function twentyfourteen_list_authors() {
    $contributor_ids = get_users( array(
        'fields'  => 'ID',
        'orderby' => 'post_count',
        'order'   => 'DESC',
        'who'     => 'authors',
    ) );

    foreach ( $contributor_ids as $contributor_id ) :
        $post_count = count_user_posts( $contributor_id );

        // Move on if user has not published a post (yet).
        if ( ! $post_count ) {

    <div class="contributor">
        <div class="contributor-info">
            <div class="contributor-avatar"><?php echo get_avatar( $contributor_id, 132 ); ?></div>
            <div class="contributor-summary">
                <h2 class="contributor-name"><?php echo get_the_author_meta( 'display_name', $contributor_id ); ?></h2>
                <p class="contributor-bio">
                    <?php echo get_the_author_meta( 'description', $contributor_id ); ?>
                <a class="button contributor-posts-link" href="<?php echo esc_url( get_author_posts_url( $contributor_id ) ); ?>">
                    <?php printf( _n( '%d Article', '%d Articles', $post_count, 'twentyfourteen' ), $post_count ); ?>
            </div><!-- .contributor-summary -->
        </div><!-- .contributor-info -->
    </div><!-- .contributor -->


Simply call it in your template files as

share|improve this answer
You could also add a status parameter – Brad Dalton Aug 16 '14 at 12:22
IIRC that display users that have capability to post, not user that have effectively posted something. – gmazzap Aug 16 '14 at 12:28
I'm referring to if have published posts if ( ! $post_count ) { continue; – Brad Dalton Aug 16 '14 at 12:32
Pieter, I think I can improve performance of your function, look at my answer ;) – gmazzap Aug 16 '14 at 13:30
count_many_users_posts() function should be used for efficiency, when counting for a set of multiple users. – Rarst Jul 12 at 7:35

There is no default way in WordPress to do this task, as Pieter Goosen pointed out, exists the argument who for get_users() that returns users that can post, not the users that have posted.

However, you can use 'pre_user_query' to add a JOIN SQL clause to only get users that have at least one post.

To be honest, when you query users ordering them by post count, the join is already created by WordPress, but using an OUTER LEFT JOIN, so even users with no posts are returned, so the only thing you need is to replace the OUTER LEFT JOIN to a INNER JOIN

function filter_users_have_posted( $user_query ) {
   $user_query->query_from = str_replace( 'LEFT OUTER', 'INNER', $user_query->query_from );
   remove_action( current_filter(), __FUNCTION__ );

add_action( 'pre_user_query', 'filter_users_have_posted' );

$blogusers = get_users( 'orderby=post_count&order=desc' );
share|improve this answer
Must you burst my bubble, lol :-). Great answer, must say. Never thought in that direction to be honest. +1 – Pieter Goosen Aug 16 '14 at 13:48
Thats great information to know! Thanks for your help. Just tried your solution and that also gets me close to where I need to be. :) – steakpi Aug 16 '14 at 13:48

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.