从其他作者的帖子中获得我所有的评论- WordPress



我从其他作者的帖子中获取所有评论并显示在我自己的帖子中有问题。我做了一个循环来捕获其他作者的所有帖子,并成功地显示在我自己的帖子中。在每个帖子的下面,我想显示我所有的评论,只过滤我的评论,但结果显示其他作者的所有评论。

下面是我用来捕获循环单个模板内所有注释的代码:

/** This is outside loop to capture my own author email not from within loop which is from other author's post **/
 $MyEmail =  the_author_email();
/** This is inside loop **/
<?php       
$args = array(
        'post_id' => $post->ID,                                        
        'author_email' => $MyEmail,
        /** When I used comment_id it will displays all comments even I used my comment_id taken from outside the loop. Using 'author_email no comments displayed **/               
);
$comments = get_comments($args);
foreach($comments as $comment) :                    
    echo   ($comment->comment_content);
endforeach;
?>

尝试函数get_the_author_meta()

$MyEmail =  get_the_author_meta( 'user_email',$post->post_author);
$args = array(
        'post_id' => $post->ID,                                        
        'author_email' => $MyEmail
);
$comments = get_comments($args);
foreach($comments as $comment) :                    
    echo   ($comment->comment_content);
endforeach;

最新更新