如何从一篇帖子中获取所有评论作者?
我正在构建一个插件,当有人对某个帖子发表评论时,我想通知该帖子的作者,但如果另一个人添加了评论,我想通知该帖子的作者以及该帖子上其他评论的作者。
我需要一个数组中的帖子作者和所有评论作者的电子邮件,我可以给他们发送电子邮件。
如何从一篇帖子中获取所有评论作者?
我正在构建一个插件,当有人对某个帖子发表评论时,我想通知该帖子的作者,但如果另一个人添加了评论,我想通知该帖子的作者以及该帖子上其他评论的作者。
我需要一个数组中的帖子作者和所有评论作者的电子邮件,我可以给他们发送电子邮件。
写一个循环并浏览每个评论是我可以提供给你的选择。看看这个例子:
function get_comment_authors($post_ID){
// Get every comment on this post
$args = array(
\'post_id\' => $post_ID
);
$comment_objects = get_comments( $args );
// Define an empty array to store the comments
$author_array = array();
// Run a loop through every comment object
foreach ( $comment_objects as $comment ) {
// Get the comment\'s author
$author_array[] = $comment->comment_author;
}
// Return the authors as an array
return $author_array;
}
所以,get_comment_authors(123);
将返回ID为123的所有在帖子上留言的作者。是否有一种方法可以将评论显示为帖子的一部分,而不使用comments\\u template()将其添加?