【问题标题】:Get all my comments from other author post - WordPress从其他作者的帖子中获取我的所有评论 - WordPress
【发布时间】:2016-01-09 10:10:29
【问题描述】:

我在从其他作者的帖子中获取我的所有 cmets 并在我自己的帖子中显示时遇到问题。 我做了一个循环来捕获其他作者的所有帖子并成功显示在我自己的帖子中。在每篇文章的下方,我想显示我所有的 cmets 并仅针对我的 cmets 进行过滤,但结果显示其他作者的所有 cmets。

这是我用来在循环单个模板中捕获所有 cmets 的代码:

/** 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;
?>

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    试用功能: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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-14
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多