Categories
Wordpress

Get the authors list who submitted highest number of posts in wordpress

Now a days the use of wordpress content management system is not limited to a blog or a portfolio website, it is also used as a eCommerce website platform. No matter how we use it, we often need the highest post submitted author list. Using below script you can get the list of authors who submitted highest number of posts in WordPress.

<?php
    function top_authors_list($number = 10) {
        $html = '';
        $uc = array();
        $blogusers = get_users();

        if ($blogusers) {
            $html .= '<ul>';
            foreach ($blogusers as $bloguser) {
                $post_count = count_user_posts($bloguser->ID);
                $uc[$bloguser->ID] = $post_count;
            }
            arsort($uc);

            $i = 0;
            foreach ($uc as $key => $value) {
                $i++;
                if ($i <= $number) {
                    $user = get_userdata($key);
                    $author_posts_url = get_author_posts_url($key);
                    $post_count = $value;
                    if ($post_count > 0) {
                        $html .= '<li><a href="' . $author_posts_url .'">' . $user->display_name . '</a> (' . $post_count . ')</li>';
                    }
                }
            }
            $html .= '</ul>';
        }

        return $html;
    }
?>

 

 

Share with: