The MU forums have moved to WordPress.org

Get username -> how to. wordpress codex doesnt work (8 posts)

  1. denzel2364
    Member
    Posted 13 years ago #

    Hi there,

    I am currently using:

    <?php
    global $wp_query;
    $curauth = $wp_query->get_queried_object();
    ?>

    <p>This is <?php echo $curauth->ID; ?>'s page</p>
    <p>This is <?php echo $curauth->display_name; ?>'s page</p>
    <p>This is <?php echo $curauth->first_name; ?>'s page</p>
    <p>This is <?php echo $curauth->last_name; ?>'s page</p>
    <p>This is <?php echo $curauth->user_nicename; ?>'s page</p>

    but it wont pick anything up apart from ID. I need it to show the user's username in the template.

    not even -> this works <?php the_author(); ?>

  2. denzel2364
    Member
    Posted 13 years ago #

    no idea??

  3. SteveAtty
    Member
    Posted 13 years ago #

    I do it this way

    $user_info = get_userdata($user_id);
    $author_nice=$user_info->display_name;
    $author_nick=$user_info->nickname;
    $author_first=$user_info->first_name;
    $author_last=$user_info->last_name;

    and you can get the user_id of the post from the post data:

    $post = get_post($post_id);
    $user_id=$post->post_author;
  4. denzel2364
    Member
    Posted 13 years ago #

    Thanks Steve,

    I tried adding this to my page:

    <?php
    $user_info = get_userdata($user_id);
    $author_nice=$user_info->display_name;
    $author_nick=$user_info->nickname;
    $author_first=$user_info->first_name;
    $author_last=$user_info->last_name;
    ?>

    But no username displays. Is there something i am writing wrong?

  5. andrea_r
    Moderator
    Posted 13 years ago #

    you're not echoing the results.

  6. denzel2364
    Member
    Posted 13 years ago #

    I dont understand it:

    <?php
    $user_info = get_userdata($user_id);
    $author_nice=$user_info->display_name;
    $author_nick=$user_info->nickname;
    $author_first=$user_info->first_name;
    $author_last=$user_info->last_name;
    ?>

    Test:<?php echo "$author_nice" ?>

  7. SteveAtty
    Member
    Posted 13 years ago #

    Is the user_id set ?

    Did you do:

    $post = get_post($post_id);
    $user_id=$post->post_author;

    first?

  8. denzel2364
    Member
    Posted 13 years ago #

    Thats perfect, thanks Steve

    .....

    <?php
    $post = get_post($post_id);
    $user_id=$post->post_author;
    ?>
    
    <?php
    $author_first=$user_info->first_name;
    ?>
    
    Result:<?php echo "$author_first" ?>

    ........

About this Topic

  • Started 13 years ago by denzel2364
  • Latest reply from denzel2364