Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

From the users section, I can see a link to their posts, but not their comments. When I go to comments, there doesn't seem to be a straightforward way to filter only comments by a specific user. How to do it? (I'm sure such basic feature must be somewhere, I just can't find it.)

share|improve this question
add comment

1 Answer

Afaik, there's no straight forward way for this.

You'd have to extend the WP_List_Table and add an extra column. This would be an example function:

function wpse_get_comments_by_user( $user_ID )
{
    global $wpdb;

    $rows = $wpdb->query( $wpdb->prepare(
         "
            SELECT * 
            FROM %s
            WHERE user_id = %d
         "
        ,$wpdb->comments
        ,(int) $user_ID
    ) );

   return $rows;
}

The above ↑ function gives you back all DB rows for comments by the user you specified by her/his ID.

You then can go and list for e.g. all posts in a foreach loop:

foreach ( wpse_get_comments_by_user( $user->ID ) as $comment )
{
    $post_link = get_permalink( $comment->comment_post_ID );

    echo "<a href='{$post_link}'>";
        // apply the excerpt filters in case the comment content is too long
        echo apply_filters( 'the_excerpt', $comment->comment_content );
        // Add the date
        echo $comment->comment_date;
    echo '</a>';
}

The actual problem is that there's no admin screen where you can list comments by user. So I'd say it'd be easier to do this with a link and a page-template where you hide the contents behind current_user_can( 'manage_options' );.

share|improve this answer
    
Great, thanks. I think the Admin / Users page would be a good place for this. –  Borek Feb 29 '12 at 17:10
add comment

Your Answer

 
discard

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.