Skip to content

WordPress: List all authors with at least one post (or post type)

with this snippet, you can list all authors with at least one post (or post type). You can change the first line with your post type, and accommodate html tags as needed.

 <?php


                $post_type = 'post'; /* Your Post type ex: post */
                global $wpdb;

                $all_authors = $wpdb->get_results(
                "select
                A.*, COUNT(*) as post_count
                from
                $wpdb->users A
                inner join $wpdb->posts B
                on A.ID = B.post_author
                WHERE ( ( B.post_type = '$post_type' AND ( B.post_status = 'publish' OR B.post_status = 'private' ) ) )
                GROUP BY A.ID
                ORDER BY post_count DESC"
                );

                if ($all_authors) {
                    foreach ($all_authors as $aut) { ?>
                        <div class="author">
                            <div class="author__img">
                                <?php
                                echo '<a href="' . get_author_posts_url($aut->ID, $aut->user_nicename) . '" title="' . esc_attr(sprintf(__("Author Bio for %s"), $aut->display_name)) . '">';
                                ?>
                                <img src="<?php echo $author_avatar = get_field('user_avatar', 'user_' . $aut->ID); ?>">
                                </a>
                            </div>
                            <h4>
                                <?php
                                echo '<a href="' . get_author_posts_url($aut->ID, $aut->user_nicename) . '" title="' . esc_attr(sprintf(__("Author Bio for %s"), $aut->display_name)) . '">';
                                ?> <?php echo $aut->display_name; ?></a>
                            </h4>
                        </div>


                <?php  }
                }
                ?>