WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating an author.php page and I'd like to show comments as well as posts from a custom post type. I already have the list of posts but I'm looking into an efficient way of displaying the most recent comments from that author as well. So far I haven't found anything except widget and bloated plugins.

I'd like to do that particularly in one stream (posts/comments) but I can understand if this is too challenging :)

Thanks! Dennis

share|improve this question
Thanks for bringing this to my attention, I'll make sure to mark my posts next time. – FLX Jun 8 '11 at 8:36
up vote 1 down vote accepted

This function calls all comments by an author and strips every comment to a max-length. Adjust the comment excerpt length when calling the function in your template like wpse19316_author_comments( 100 );.

function wpse19316_author_comments( $length )
    $final_length = (int) $length;
    $author_comments = get_comments( array( 'ID' => $GLOBALS['authordata']->ID ) );
    foreach ( $author_comments as $comment )
        $comment_length = sublen( $comment->comment_content );
        $comment_excerpt = $comment->comment_content;
        if ( $comment_length > $final_length )
            $comment_excerpt = substr( $comment->comment_content, $final_length );
        echo $comment_excerpt.'<br />';
share|improve this answer
Thanks Kaiser, works like a charm :) – FLX Jun 8 '11 at 9:42
@FLX You're welcome :) – kaiser Jun 8 '11 at 10:11
I am trying to get your function to work properly in our WP installation. I add the code above that you mentioned to the functions.php as cited below with standard php tags around it. And that tried to use <?php wpse19316_author_comments() ?> to display the output to an author page for a particular user on the author.php. Am I doing it right or is there something I'm missing? If you can help I would be so happy. Thanks in advance. – user9964 Nov 3 '11 at 13:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.