我试图在“作者”页面中显示作者评论列表,但它只显示未发表的评论。
如何在作者页面中列出用户评论?
<?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";} ?>
SO网友:jgraup
尝试使用WP_Comment_Query 确保你有权Author ID 从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.\';
}