Support » Plugin: Co-Authors Plus » Sort Authors by Post Count when using Co-Authors Plus

  • ddcbronx55


    Great plugin…thank you!

    I have the below code working perfectly, as it pulls in the ‘top authors’ on our site. It will display the author avatar, name, and details of the author with the most posts published on the site. And beyond that it will continue to the 2nd most, 3rd most…etc.

    The issue I am having is author #1 for instance has 3 articles published on his own. Author #2 has 5 articles on his own. Author #1 and #3 as ‘co authors’ have an additional 3 articles published together.

    In the ‘count’ the totals show up as author #2 with 5, author #1 with 3, author #3 with 0. And I’m guessing, although not seen, that author #1 and #3 have 3 ‘together’.

    Is it possible to include the ‘co-author’ articles as part of the non-co author so that Author #1 would show up first with 6 total articles?

    global $wpdb;
    $top_authors = $wpdb->get_results("
    	SELECT u.ID, count(post_author) as posts FROM {$wpdb->posts} as p
    	LEFT JOIN {$wpdb->users} as u ON p.post_author = u.ID
    	WHERE p.post_status = 'publish'
    	AND p.post_type = 'post'
    	GROUP by p.post_author
    	ORDER by posts DESC
    	LIMIT 1,1
    if( !empty( $top_authors ) ) {
    	echo ' ';
    	foreach( $top_authors as $key => $author ) {
    		echo '	<article class="hitArea grid1x1 grid1-grad1 "><figure><a href="' . get_author_posts_url( $author->ID ) . '">
    			 ' . get_avatar( $author->ID , 235 ) . '
    	echo '<figcaption><h2>' . get_the_author_meta( 'user_nicename' , $author->ID ) . '</a></h2><p>'. get_cimyFieldValue( $author->ID, 'DETAILS' ) .'</p>	<a href="###" class="view">Learn More</a></figcaption></figure></article>' ;

    Would having this in the code help at all?
    <?php foreach( get_coauthors() as $coauthor ) : ?>


Viewing 1 replies (of 1 total)
  • ddcbronx55


    Looking at it more, it appears to be giving the post count to the author who is listed first on the co-author plugin.

    So if there is an article by Author #1 and #3, and #3 is listed first on the plugin, author #1 does not get credit in the post count for this article.

Viewing 1 replies (of 1 total)
  • The topic ‘Sort Authors by Post Count when using Co-Authors Plus’ is closed to new replies.