Show authors latest comments on author.php

I have a WordPress site and I’ve set up an author.php page where a users information is displayed.

Currently I’ve managed to get it to show the authors latest posts they’ve add to the site using query_posts.

Read More

However, I want this page to also show the authors latest comments he has posted on the site, but I can’t seem to figure out how to do it with a query, as I’m not sure if WordPress supports this feature.

Related posts

Leave a Reply

1 comment

  1. There’s a function for this: get_comments.

    Example usage (based on the Codex example):

    $auth_id = get_the_author_meta( 'ID' );
    $defaults = array(
        'author_email' => '',
        'ID' => '',
        'karma' => '',
        'number' => '',
        'offset' => '',
        'orderby' => '',
        'order' => 'DESC',
        'parent' => '',
        'post_ID' => '',
        'post_id' => 0,
        'post_author' => '',
        'post_name' => '',
        'post_parent' => '',
        'post_status' => '',
        'post_type' => '',
        'status' => '',
        'type' => '',
        'user_id' => $auth_id,
        'search' => '',
        'count' => false,
        'meta_key' => '',
        'meta_value' => '',
        'meta_query' => '',
    );
    $auth_comments = get_comments( $defaults );
    var_dump( $auth_comments );
    

    Important note: avoid using query_posts, see: When should you use WP_Query vs query_posts() vs get_posts()?