[wp-trac] [WordPress Trac] #14408: Get author information in author template file without having to query the first post

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 24 13:51:46 UTC 2010

#14408: Get author information in author template file without having to query the
first post
 Reporter:  garyc40       |       Owner:                 
     Type:  defect (bug)  |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:  3.0            
 Severity:  normal        |    Keywords:                 
 In the template file author.php, Twenty Ten queries the first post of the
 author to get the author's profile information. This introduces a bug when
 the author has no blog posts yet, then the global $authordata is not set,
 as a result, no author information is displayed. Also, having to rewind
 the query later in the template is counter-intuitive.

 One may argue that there's no need to display author information if that
 author doesn't have any blog posts yet. But I disagree. Theme developers
 might want to list custom posts on the author template file as well. For
 some sites, the author page is served as a member profile page for
 subscribers. Therefore having to query the first post in order to get the
 requested author information is a flawed approach.

 One better way to fetch author information in the author template is by
 getting the query var 'author' for the author ID. Then use
 get_author_meta() with the second parameter to get the desired

 $author_id = get_query_var( 'author' );
 $author_description = get_the_author_meta( 'description', $author_id );

 I attached a patch that addresses this issue.

 In this patch, get_author_meta() is also modified to handle the
 "display_name" field correctly by applying the filter "the_author"
 whenever this field is fetched.

 Another approach, which I haven't tested yet, is to set the $authordata
 global variable whenever the author query var is set. If that's possible,
 then we no longer need to supply $author_id to get_the_author_meta(). If
 anyone is interested in testing this approach, go ahead and create a

Ticket URL: <http://core.trac.wordpress.org/ticket/14408>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list