Parent comment’s author display_name

Parent comment’s author name

I found this code and would like to modify it as follows: if someone changes the display_name, the name in the comments should also change.
I was able to achieve this with the following code in the comments:

$usermeta = get_userdata($comment->user_id);

<?php echo $usermeta->display_name?>

However, I don’t know how to change the code below to show display_name here as well.

if( $comment->comment_parent )
comment_author( $comment->comment_parent );

I appreciate any help.

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

So to do the same thing but for the parent comment this should do it. This is untested but does the same thing as your first case, but with the parent comment object instead of the current comment.

if( $comment->comment_parent ) {
    $parentComment = get_comment($comment->parent);
    $usermeta = get_userdata($parentComment->user_id);
    echo $usermeta->display_name ; 
}

Does that do it?

Method 2

Oh, I got it!

if( $comment->comment_parent ) {
    $parent_ID = $comment->comment_parent;
    $parent_comment = get_comment($parent_ID);
    $parent_usermeta = get_userdata($parent_comment->user_id);
    echo $parent_usermeta->display_name; }


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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x