admin管理员组文章数量:1291041
I need to put the name of the author who wrote the post and I can't find the solution.
EXAMPLE:
Rachel [06/03/21] : Commented in the post "How to be a Web Designer", written by: POSTAGE AUTHOR - Test Comment
<?php
$args = array(
'user_id' => bp_current_user_id(),
'number' => 20, // how many comments to retrieve
'status' => 'approve'
);
$comments = get_comments( $args );
if ( $comments )
{
$output.= "<ul>\n";
foreach ( $comments as $c )
{
$output.= '<li>';
$output.= $c->comment_author;
$output.= ' [';
$output.= mysql2date('d/m/y', $c->comment_date, $translate);
$output.= '] ';
$output.= ' : ';
$output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
$output.= get_the_title($c->comment_post_ID);
$output.= "</a>";
$output.= ' - ';
$output.= $comment->user_id;
$output.= $c->comment_content;
$output.= "</li>\n";
}
$output.= '</ul>';
echo $output;
} else { echo "No comments made";}
?>
I need to put the name of the author who wrote the post and I can't find the solution.
EXAMPLE:
Rachel [06/03/21] : Commented in the post "How to be a Web Designer", written by: POSTAGE AUTHOR - Test Comment
<?php
$args = array(
'user_id' => bp_current_user_id(),
'number' => 20, // how many comments to retrieve
'status' => 'approve'
);
$comments = get_comments( $args );
if ( $comments )
{
$output.= "<ul>\n";
foreach ( $comments as $c )
{
$output.= '<li>';
$output.= $c->comment_author;
$output.= ' [';
$output.= mysql2date('d/m/y', $c->comment_date, $translate);
$output.= '] ';
$output.= ' : ';
$output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
$output.= get_the_title($c->comment_post_ID);
$output.= "</a>";
$output.= ' - ';
$output.= $comment->user_id;
$output.= $c->comment_content;
$output.= "</li>\n";
}
$output.= '</ul>';
echo $output;
} else { echo "No comments made";}
?>
Share
Improve this question
asked Jun 3, 2021 at 21:45
Patrique UiliamPatrique Uiliam
33 bronze badges
0
1 Answer
Reset to default 0Not sure it's the shortest way, but it works)
Get post author id
$post_author_id = get_post_field( 'post_author', $c->comment_post_ID );
Get author data by id
$post_author_display_name = get_the_author_meta( 'display_name', $post_author_id );
Try this shorter version
$output.= get_the_author_meta( 'display_name', get_post_field( 'post_author', $c->comment_post_ID ) );
Check documentation page which data is available with get_the_author_meta()
本文标签: functionsHow to put the author of the post in the comments
版权声明:本文标题:functions - How to put the author of the post in the comments? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741522981a2383298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论