admin管理员组文章数量:1296312
I'm trying to display a list of the author comments in the authors page but it only shows No comments made.
How can I list user comments in the authors page?
<?php
$args = array(
'user_id' => $user->ID,
'number' => 10, // how many comments to retrieve
'status' => 'approve'
);
$comments = get_comments( $args );
if ( $comments )
{
$output.= "<ul>\n";
foreach ( $comments as $c )
{
$output.= '<li>';
$output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
$output.= get_the_title($c->comment_post_ID);
$output.= '</a>, Posted on: '. mysql2date('m/d/Y', $c->comment_date, $translate);
$output.= "</li>\n";
}
$output.= '</ul>';
echo $output;
} else { echo "No comments made";} ?>
I'm trying to display a list of the author comments in the authors page but it only shows No comments made.
How can I list user comments in the authors page?
<?php
$args = array(
'user_id' => $user->ID,
'number' => 10, // how many comments to retrieve
'status' => 'approve'
);
$comments = get_comments( $args );
if ( $comments )
{
$output.= "<ul>\n";
foreach ( $comments as $c )
{
$output.= '<li>';
$output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
$output.= get_the_title($c->comment_post_ID);
$output.= '</a>, Posted on: '. mysql2date('m/d/Y', $c->comment_date, $translate);
$output.= "</li>\n";
}
$output.= '</ul>';
echo $output;
} else { echo "No comments made";} ?>
Share
Improve this question
edited Dec 20, 2015 at 21:58
Sven
3,6841 gold badge35 silver badges48 bronze badges
asked Dec 20, 2015 at 18:52
Frank OlsonFrank Olson
114 bronze badges
1
|
1 Answer
Reset to default 2Try with WP_Comment_Query and make sure you have the right Author ID from the Author Template.
// WP_Comment_Query arguments
$args = array (
'user_id' => $user->ID,
'post_status' => 'approve',
'number' => '10',
);
// The Comment Query
$comments = new WP_Comment_Query;
$comments = $comments->query( $args );
// The Comment Loop
if ( $comments ) {
$output.= "<ul>\n";
foreach ( $comments as $c ) {
$output.= '<li>';
$output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
$output.= get_the_title($c->comment_post_ID);
$output.= '</a>, Posted on: '. mysql2date('m/d/Y', $c->comment_date, $translate);
$output.= "</li>\n";
}
$output.= '</ul>';
echo $output;
} else {
echo 'No comments found.';
}
本文标签: List user comments in author page
版权声明:本文标题:List user comments in author page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741618974a2388695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$user->ID
set ? What happens if you remove the'user_id'
part? I assume you got plenty of approved comments. – birgire Commented Dec 20, 2015 at 19:12