Each and every blog posts and pages in WordPress is written by a author or blogger, and hence has an author ID associated with it. Within the loop, the_author_meta(‘ID’); (previously the_author_ID();) template tag and the_author(); or get_the_author(); functions can be used to retrieve, obtain or get the author ID and profile for further manipulation, though must be inside the loop of WordPress.
Outside the loop, the_author_meta( $field, $userID ); can be specified with a author ID or user ID in order to return the name and profile meta of the user. However, as it’s outside of the loop, the author ID must first be obtained in order to feed the the_author_meta function.
Here’s how to obtain and get the author ID outside the WordPress loop:
Then, in order to retrieve name or other meta profile of the author ID, just use the the_author_meta(); template tag:
the_author_meta( $field, $author_id );
Replace meta name with a valid parameter that available as field name. The $field represent a meta data that associate with the author or user, such as login name, display name, nickname, and etc. List of valid values for the field name includes:
The code above also supports a multi-users WordPress blog where there is multiple authors. Note that the code should be used on a single post or page templates, and can be used in sidebar, plugin, widget, theme function and other areas.