logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
SQL-query for getting a top authors by qty of received comments

Is there way to get a list of authors by quantity of received comments?

e.g.

Author ID - 7 comments received
Author ID - 5 comments received
Author ID - 1 comment received

This question has been answered.

Igor | 05/31/12 at 10:31pm Edit

Previous versions of this question: 05/31/12 at 10:50pm

(4) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/31/12
    10:36pm
    Agus Setiawan says:

    hi,

    you can use this plugin : http://wordpress.org/extend/plugins/top-contributors/

    • 05/31/12 10:43pm

      Igor says:

      Hi Agus,

      Unfortunately, nope.

      That plugin allow to display:
      - Top contributors by comments
      - Top author by posts

      I need a top authors by comments. Just a SQL-query will be fine for me.

  • avatar
    Last edited:
    06/01/12
    12:15am
    Arnav Joy says:

    try this

    <?php

    global $wpdb;
    $res = $wpdb->get_results( "SELECT user_id,count(user_id) AS nb FROM $wpdb->comments group by user_id ORDER BY nb DESC" );
    if(!empty($res)){
    foreach ($res as $ud){
    echo 'Author ID'. ' - '.$ud->user_id .' , ' .$ud->nb.' comments received'.'<br>';
    }
    }
    ?>

    • 06/01/12 9:42am

      Igor says:

      Hi Arnav,

      That works like a charm! Thank you so much! I'm really appreciated.

    • 06/01/12 9:59am

      Igor says:

      Is there way to take into account the type of post?

      Authors is a group of users who have an entries with posts_type POST.

  • avatar
    Last edited:
    06/01/12
    2:10am
    Reland Pigte says:

    Try this one Igor :

    <?php	
    $query = $wpdb->get_results( "SELECT user_id, count( user_id ) AS comment_received FROM $wpdb->comments GROUP BY user_id ORDER BY comment_received DESC LIMIT 0, 10" );
    if($query){
    foreach ($query as $res){
    echo 'Author '.$res->user_id.' - '.$res->comment_receved.' comments received'.'<br/>';
    }
    }
    ?>


    I think Arnav is right..

    Previous versions of this answer: 06/01/12 at 2:10am

  • avatar
    Last edited:
    06/01/12
    4:57am
    John Cotton says:

    I'm not sure Arnav is right....I think Igor is asking for the post author who has received the most comments for his posts...

    If that's what is wanted, then the SQL would be:

    SELECT u.display_name, u.id, COUNT(c.comment_id) AS comment_count FROM wp_users u INNER JOIN wp_posts p ON p.post_author = u.id INNER JOIN wp_comments c ON c.comment_post_ID = p.id GROUP BY u.display_name, u.id ORDER BY comment_count DESC

This question has expired.



Gabriel Reguly, Igor, Francisco Javier Carazo Gil voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.