WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] User first name (8 posts)

  1. jossi
    Member
    Posted 5 years ago #

    In the comments loop, I need to display the user first name (which is required during registration) instead of the login user name, or the user chosen display name.

    So instead of
    <?php comment_author_link() ?></cite> Says:

    I will need <? php //echo here the first name of author; ?> ?></cite> Says:`

    Any ideas?

  2. jossi
    Member
    Posted 5 years ago #

    Any ideas how to solve this, I have looked everywhere and cannot find a solution for this.

  3. equaldesign
    Member
    Posted 5 years ago #

    It should display whatever the commenter put into the name box in the comments form. If you are logged in then it uses your display name. Wouldn't that do?

  4. jossi
    Member
    Posted 5 years ago #

    My blog requires registration, so all users have a username which is displayed in the comment.

    What I need, is that instead of the user name, the first name of the user is displayed. (I am forcing users to register with first name and last name.)

    I have been checking the docs, and I can see that this information is not stored on the wp_comments table, so I will need to:
    a. Get the ID of the commenter
    b. Use the ID to retrieve the first name using get_usermeta

    <?php $commenter_name = get_usermeta($commenter_ID,'first_name'); ?>

    The question is how do I get the user_ID of the commenter?

  5. jossi
    Member
    Posted 5 years ago #

    I can see that wp-comments-post.php uses the display name:

    $comment_author = $wpdb->escape($user->display_name);

    I could change this to
    $comment_author = $wpdb->escape($user->fist_name);

    But I just do not want to change that and mess with core files.... and also this will mean that only new comments will have the first name displayed, and I need to be able to make it work with existing comments.

  6. jossi
    Member
    Posted 5 years ago #

    Got it.

    Changed my comments template to use this:

    <?php
    	$commenter_id = $comment->user_id;
            $commenter_name =  get_usermeta($commenter_id,'first_name');
    ?>
    			<cite><?php echo $commenter_name; ?></cite> Says:
  7. jossi
    Member
    Posted 5 years ago #

    This will display the first name, the first letter of the last name, nicely formatted:

    <?php
    	$commenter_id = $comment->user_id;
    	$commenter_fname =  get_usermeta($commenter_id,'first_name');
    	$commenter_lname =  substr(get_usermeta($commenter_id,'last_name'), 0, 1);
    	$commenter_name = ucwords(strtolower($commenter_fname . " " . $commenter_lname . "."));
    ?>
  8. ejk
    Member
    Posted 5 years ago #

    Thanks! This helped me.

Topic Closed

This topic has been closed to new replies.

About this Topic