Home / comment / Total user comments
  • How to Total user comments

    no thumbnail sorry: Total user comments

    Add the first block of PHP code to your functions.php then add the second block into your comments.php in the location you wish to display the total number of author comments. Another great little snippet from problogdesign.com

    ( click code to copy )

    wordpress snippet : PHP - functions.php

    <>
    function commentCountAuthor(){
    	$oneText = 'One comment';
    	$moreText = '% comments';
    	global $wpdb;
    	$result = $wpdb->get_var('
    		SELECT
    			COUNT(comment_ID)
    		FROM
    			'.$wpdb->comments.'
    		WHERE
    			comment_author_email = "'.get_comment_author_email().'"'
    	);
    	if($result == 1):
    		echo str_replace('%', $result, $oneText);
    	elseif($result > 1):
    		echo str_replace('%', $result, $moreText);
    	endif;
    }
    
    ( click code to copy )

    wordpress snippet : PHP

    <>
    <?
            commentCountAuthor();
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    author_email, comment_author, get_comment_author, get_comment_author_email, get_comment, comment_ID, _e, wp,