1

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.

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.

4

1 回答 1

0

有一个功能:get_comments.

示例用法(基于 Codex 示例):

$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 );

重要说明:避免使用query_posts,请参阅: 何时应使用 WP_Query vs query_posts() vs get_posts()?

于 2013-03-12T18:02:20.163 回答