I am trying to get the author name of current author archive:
if (is_author()) return AUTHOR_NAME;
But how can I get current author name?
I am trying to get the author name of current author archive:
if (is_author()) return AUTHOR_NAME;
But how can I get current author name?
You must be logged in to post a comment.
There is actually an interesting trick to this one.
In an author archive, the one thing you know about all the posts in the query is that they are all by the author you want. In any case, the function you will want is get_the_author().
If you want the author name after you have already entered (and even exited) the loop, the last post that was loaded will be by the author, and using get_the_author() will be enough.
If, on the other hand, you want the author’s name before you have entered the loop, you need to load the first post’s data, and then rewind the query before the loop is entered as so:
If you don’t need the loop at all, you can skip the rewinding.
If there are no posts in the query, you will have a slightly tougher job.
You can do it this way:
No
rewind_posts()
tricks needed:This will display the author of the current page/post: