WordPress.org

Ready to get started?Download WordPress

Forums

How to Exclude admin from the commenters list (1 post)

  1. Tara
    Member
    Posted 3 years ago #

    I use this hack to display 5 top commrnters. I works great.

    The code also display admin in the list.

    Can someone please guide me how to exclude admin from the list. Thnks.

    The code is:

    function top_comment_authors($amount = 5) {  
    
        global $wpdb;
        $results = $wpdb->get_results('
            SELECT
                COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
            FROM
                '.$wpdb->comments.'
            WHERE
                comment_author_email != "" AND comment_type = "" AND comment_approved = 1
            GROUP BY
                comment_author_email
            ORDER BY
                comments_count DESC, comment_author ASC
            LIMIT '.$amount
        );
    $output = "<ul>";
        foreach($results as $result){
            $output .= "<li>".(($result->comment_author_url) ? "<a href='".$result->comment_author_url."'>" : "").$result->comment_author.(($result->comment_author_url) ? "</a>" : "")." (".$result->comments_count.")</li>";  
    
        }
        $output .= "</ul>";
        echo $output;
    }

    OR
    You may have better hack that also excludes the admin, please share. thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.