How to display list of replies to his comments in user profile of current user. my website can send notification that example: “someone replied to your comment” and when i click the link that was sent by notification email it forward me to comment page. i also want to list these replies in user profile.
thanks for attention
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I also have a page where I list comments and replies to the current user comments.
I might not be able to explain the answer very well, but this is what I did. I listed all the comments of the current user and listed again the comments with the parent_id of the current user’s comments.
$comments = get_comments( array(
'user_id' => (get_current_user_id()),
'status' => array( 'approve', 'hold' ),
'type' => 'comment'
)
);
foreach ( $comments as $comment ) {
echo $comment->comment_content;
$parent_id = $comment->comment_ID;
$replies = get_comments( array(
'status' => array( 'approve', 'hold' ),
'type' => 'comment',
'parent' => $parent_id
)
);
foreach ( $replies as $reply ) {
echo $reply->comment_author;
echo $reply->comment_content;
}
}
In a WordPress environment this is the best way I have come up with.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0