Display Authors Comments on Profile Page

I am trying to display authors comments on their profile page (author.php), however both codes I tried seem to display everyone’s comments. Also the second code is suppose to link to the specific comment, but instead it does nothing. Also the comments id is already added to the comments output and it prints fine. Any help is greatly appreciated.

// Method 1
<ul class="authpcom">
<?php
$author_email = get_the_author_meta( 'user_email' ); 

$args = array(
    'author_email' => $author_email
);
$comments = get_comments($args);
foreach($comments as $comment) :
    echo('<a href=" ' . get_permalink($comment->post_ID) . ' " rel="external nofollow" title=" ' . $title . ' ">' .$title . '</a><br />' . $comment->comment_date . '<br /><li>' . $comment->comment_content . '</li>');
endforeach;
?>
</ul>


// Method 2
<?php   $comments = get_comments(); ?>
<ul id="recent_comments">
<?php foreach ($comments as $comment) { ?>
<li><p><strong><?php
        $title = get_the_title($comment->comment_post_ID);
        echo get_avatar( $comment, '45' );
echo strip_tags($comment->comment_author); ?></strong>&nbsp;commented on <a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php echo $comment->comment_ID; ?>" rel="external nofollow" title="<?php echo $title; ?>"> <?php echo $title; ?></a>: <?php echo wp_html_excerpt( $comment->comment_content, 45 ); ?> (...)</p></li>
<?php }  ?>
</ul>

Used on comment output divs –

$comment->comment_ID

object(WP_User)#345 (7) { [“data”]=> object(stdClass)#344 (10) {
[“ID”]=> string(1) “2” [“user_login”]=> string(6) “agent1”
[“user_pass”]=> string(34) “$P$BXUSPFSBfmyIrjZ2YUnbIs1GwjkdH50”
[“user_nicename”]=> string(6) “agent1” [“user_email”]=> string(19)
“agent1@homekast.com” [“user_url”]=> string(0) “”
[“user_registered”]=> string(19) “2015-07-25 10:33:27”
[“user_activation_key”]=> string(0) “” [“user_status”]=> string(1) “0”
[“display_name”]=> string(9) “John Paul” } [“ID”]=> int(2) [“caps”]=>
array(1) { [“agent”]=> bool(true) } [“cap_key”]=> string(15)
“tr_capabilities” [“roles”]=> array(1) { [0]=> string(5) “agent” }
[“allcaps”]=> array(2) { [“read”]=> bool(true) [“agent”]=> bool(true)
} [“filter”]=> NULL }

Solutions Collecting From Web of "Display Authors Comments on Profile Page"

What you need to use here is the WP_Comment_Query() function.

So on the author.php page, you can easily get the author info and ID as followed:

// get author info
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));

// set ID
$user_id = $curauth->ID;

Then we add the user ID in the query arguments array:

$args = array(
    'user_id' => $user_id, // comments by this user only
    'status' => 'approve',
    'post_status' => 'publish',
    'post_type' => 'post'
);

And finally we hit the arguments in the wp_comment_query():

// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );

// Comment Loop
if ( $comments ) {
    foreach ( $comments as $comment ) {
        echo '<p>' . $comment->comment_content . '</p>';
    }
} else {
    echo 'No comments found.';
}

As an added bonus, I investigated how pagination works with wp_comment_query() for not long ago and offer a good solution here. It was a little bit of a fiddle-niddle to make it work.

EDIT:

A better way to get the author ID is simply with (props @Pieter):

$user_id = get_queried_object_id();

First method, you are missing the second parameter for get_the_author_meta, which is the ID of the author.

Second method, you are using undefined variables.. Check this code, should get you what you want.

// Method 1
<ul class="authpcom">
    <?php
        $queried_object = get_queried_object();
        $author_email = get_the_author_meta( 'user_email', $queried_object->ID ); 

        $args = array(
            'author_email' => $author_email
        );
        $comments = get_comments($args);
        foreach($comments as $comment) :
            echo '<a href=" ' . get_permalink( $comment->comment_post_ID ) . ' " rel="external nofollow" title=" ' . get_the_title( $comment->comment_post_ID ) . ' ">' . get_the_title( $comment->comment_post_ID ) . '</a><br />' . $comment->comment_date . '<br /><li>' . $comment->comment_content . '</li>';
        endforeach;
    ?>
</ul>


// Method 2
<?php
    $comments = get_comments();
?>
<ul id="recent_comments">
<?php foreach ($comments as $comment) { ?>
<li>
    <p>
        <strong>
        <?php
            echo get_avatar( $comment->comment_author_email, '45' );
            echo strip_tags($comment->comment_author);
        ?>
        </strong>
        &nbsp;commented on <a href="<?php echo get_permalink( $comment->comment_post_ID ); ?>#comment-<?php echo $comment->comment_ID; ?>" rel="external nofollow" title="<?php echo get_the_title( $comment->comment_post_ID ); ?>"> <?php echo get_the_title( $comment->comment_post_ID ); ?></a>: <?php echo wp_html_excerpt( $comment->comment_content, 45 ); ?> (...)
    </p>
</li>
<?php }  ?>
</ul>

EDIT: (09/05/2015)

// Method 1
<ul class="authpcom">
    <?php
        $authorID = get_queried_object_id();
        $author_email = get_the_author_meta( 'user_email', $authorID ); 

        $args = array(
            'user_id' => $authorID,
        );
        $comments = get_comments($args);
        if ( $comments ) {
            foreach($comments as $comment) {
                echo '<li><a href="' . get_permalink( $comment->comment_post_ID ) . '" rel="external nofollow" title="' . get_the_title( $comment->comment_post_ID ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a><br>' . $comment->comment_date . '<br>' . $comment->comment_content . '</li>';
            }
        } else {
            echo '<li>No Comments from this Author</li>';
        }
    ?>
</ul>

You can achieve this using the ultimate member plugin. It seems to be able to do a lot of things with user profiles, but also appears to be suitable to display user’s comments on the profile page.

Show author posts & comments on user profiles