显示 post 标题为 post 的登录用户评论

Show logged in users comments with post title of post

这个线程How to display logged in users comments (only) on Wordpress 已经把我带到了我想去的地方......但是,我正在尝试稍微改变它,以便它显示 post 标题而不是作者的名字并链接回 post 他们留下了评论。

这是我想出的代码,但它不起作用。

if ( is_user_logged_in() ) { 
  $user_id = get_current_user_id(); $args = array( 'status' => 'approve', 'order' =>    'DESC', 'user_id' => $user_id ); 
  $comments = get_comments($args); foreach($comments as $comment) : echo '<p>'; 
  $post_id = $comment->comment_post_ID;
  $member_name = get_post( $comment->comment_post_ID );

  echo( '<a href="<?php echo get_permalink( $comment->comment_post_ID );">' . $member_name . '</a><br />' . $comment->comment_content); 
  echo '</p>'; 
  endforeach; 
} 

不是我可以测试的地方,但你正在将 post 抓取到数组 $member_name 中。因此,要显示 post 名称,请将输出 $member_name 替换为 $member_name->post_title。

喜欢:

echo( '<a href="<?php echo get_permalink( $comment->comment_post_ID );">' . $member_name->post_title . '</a><br />' . $comment->comment_content);

也许可以将数组重命名为更清晰的名称,例如 $post。