[resolved] Problem with displaying author_name (10 posts)

  1. Jeremy Sarber
    Posted 5 years ago #

    I have this on an Authors archive page:

    <?php echo get_query_var('author_name'); ?>

    On the site, it displays the name with a hyphen like it does in the URL. For instance, Jeremy Sarber displays Jeremy-Sarber.

    What's the problem?

  2. vtxyzzy
    Posted 5 years ago #

    get_query_var() gets its values from the URL that was used to create the query. Check out the function get_the_author().

  3. Jeremy Sarber
    Posted 5 years ago #

    Thanks for the reply. Unfortunately, that leaves the name missing.

    Shows hosted by <?php $author = get_the_author(); ?>:

    Becomes this:

    Show hosted by :

  4. I'm not sure if this is the issue, but maybe worth a try: put back your original line of code, go into Users > and select a user. For each user there should be a drop-down menu where you can select how you want the name to be displayed on the public side - there should be a few options. Let me know if this helps.

  5. Jeremy Sarber
    Posted 5 years ago #

    I appreciate you trying but it didn't change anything. I believe vtxyzzy was right. It's pulling the name from the URL (domain.com/author/USER-NAME/).

    But every other string of script I've tried causes the name to go missing altogether.

  6. No worries. I should have checked some actual code first. ;-)

    This is what I use to display the author's name:

    <?php the_author(); ?>

    ...in conjunction with selecting from each user's drop-down the desired name format. Let me know if it works.

  7. Jeremy Sarber
    Posted 5 years ago #

    I just figured it out.

    I can use this:
    <?php echo $curauth->nickname; ?>

    So long as I changed some above script to this:

    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));

    Thanks for your help.

  8. Glad you found a solution. If you would please mark this thread as "resolved" it would be appreciated. Helps everyone keep better track of whose issues are still outstanding. Thanks!

  9. vtxyzzy
    Posted 5 years ago #

    OK, the_author() is only good when processing posts in the Loop. It gets the author of the current post. If you are not viewing posts, you have to use a different approach. See the Codex on Custom Author Information for some alternatives.

    EDIT: OOPS - you beat me to it.

  10. Thanks for the clarification vtxyzzy - I goofed and forgot we were talking about the author's archive page.

Topic Closed

This topic has been closed to new replies.

About this Topic