get_the_author_meta( string $field = '', int|false $user_id = false ): string
- Since
- 2.8.0, 6.9.0
- Source
wp-includes/author-template.php:167
Reads a single field from the WordPress user object for a post's author, falling back to the global $authordata when no $user_id is passed. Useful for pulling things like email, display_name, or user_registered without loading a full user object yourself. Every value passes through the dynamic get_the_author_{$field} filter before it's returned, so plugins can intercept or reformat it.
Description
Valid values for the $field parameter include:
- admin_color
- comment_shortcuts
- description
- display_name
- first_name
- ID
- last_name
- nickname
- plugins_last_view
- plugins_per_page
- rich_editing
- syntax_highlighting
- user_activation_key
- user_description
- user_email
- user_firstname
- user_lastname
- user_level
- user_login
- user_nicename
- user_pass
- user_registered
- user_status
- user_url
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$fieldstringoptional- The user field to retrieve. Default empty.Default:
'' $user_idint|falseoptional- User ID. Defaults to the current post author.Default:
false
Return value
string- The author's field from the current author's DB object, otherwise an empty string.
Code examples
Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Show the post author's email address inside the loop
Query a single post and print the author's stored email while the loop sets the global $authordata for that post.
$author_query = new WP_Query( array( 'p' => 1, 'post_type' => 'post' ) );
if ( $author_query->have_posts() ) {
while ( $author_query->have_posts() ) {
$author_query->the_post();
echo esc_html( get_the_author_meta( 'email' ) );
}
}
wp_reset_postdata();Outside a loop that has called the_post(), $authordata is unset and every field returns an empty string.
Look up a specific user's display name by ID without the loop
Pass a $user_id directly to skip $authordata entirely and pull the field straight from get_userdata().
$name = get_the_author_meta( 'display_name', 1 );
echo esc_html( $name );This works even outside The Loop because supplying $user_id makes the function call get_userdata() instead of relying on the global.
Common problems and fixes · 4
- Why does get_the_author_meta return an empty string when I call it outside the loop?
- Why does passing 'login' or 'email' work when the database column is really user_login and user_email?
- How do I change the value that get_the_author_meta returns for a specific field sitewide?
- Do I need to escape what get_the_author_meta returns before printing it?
Why does get_the_author_meta return an empty string when I call it outside the loop?
Why does passing 'login' or 'email' work when the database column is really user_login and user_email?
How do I change the value that get_the_author_meta returns for a specific field sitewide?
Do I need to escape what get_the_author_meta returns before printing it?
Alternatives and related functions
the_author_meta- When you want to echo the field directly in a template instead of getting a string back to work with.
get_the_author- When you only need the author's display name for the current post and don't want to specify a field.
get_userdata- When you need the entire WP_User object for a known user ID rather than one field at a time.
get_user_meta- When the value you want is custom user meta rather than a core column on the wp_users table.
Performance profile
How much work a call to get_the_author_meta() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 21–26
- Plugin surface
- 1 hook
- Called by
- 42
Reaches the database via get_user_by().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 30.
Third-party callbacks on 'get_the_author_{$field}' run inside this call, and their cost is not bounded by anything here.
42 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_user_by()one call below get_the_author_meta()
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_the_author_meta() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 21–24 | get_userdata(), apply_filters() |
| always | 22–26 | apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 30 instructions, 21–26 executed per call, 4 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_the_author_meta() runs, in this order:
- apply_filters( get_the_author_{$field} )filterline 195 (+28 into the body)
Filters the value of the requested user metadata.
Uses · 2
- get_userdata()Retrieves user info by user ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 42
- Twenty_Fourteen_Ephemera_Widget::widget()Outputs the HTML for this widget.
- WP_Media_List_Table::column_author()Handles the author column output.
- WP_Posts_List_Table::column_author()Handles the post author column output.
- export_wp()Generates the WXR export file for download.
- feed_links_extra()Displays the links to the extra feeds such as category feeds.
- get_author_name()Retrieve the specified author's preferred display name.
- get_profile()Retrieve user data based on field.
- get_the_archive_description()Retrieves the description for an author, post type, or term archive.
- get_the_author_ID()Retrieve the ID of the author of the current post.
- get_the_author_aim()Retrieve the AIM address of the author of the current post.
- get_the_author_description()Retrieve the description of the author of the current post.
- get_the_author_email()Retrieve the email of the author of the current post.
Show all 42
- get_the_author_firstname()Retrieve the first name of the author of the current post.
- get_the_author_icq()Retrieve the ICQ number of the author of the current post.
- get_the_author_lastname()Retrieve the last name of the author of the current post.
- get_the_author_link()Retrieves either author's link or author's name.
- get_the_author_login()Retrieve the login name of the author of the current post.
- get_the_author_msn()Retrieve the MSN address of the author of the current post.
- get_the_author_nickname()Retrieve the nickname of the author of the current post.
- get_the_author_url()Retrieve the URL to the home page of the author of the current post.
- get_the_author_yim()Retrieve the Yahoo! IM name of the author of the current post.
- render_block_core_avatar()Renders the `core/avatar` block on the server.
- render_block_core_latest_posts()Renders the `core/latest-posts` block on server.
- render_block_core_post_author()Renders the `core/post-author` block on the server.
- render_block_core_post_author_biography()Renders the `core/post-author-biography` block on the server.
- render_block_core_post_author_name()Renders the `core/post-author-name` block on the server.
- the_author_meta()Outputs the field from the user's DB object. Defaults to current post's author.
- twenty_twenty_one_posted_by()Prints HTML with meta information about theme author.
- twentyeleven_posted_on()Prints HTML with meta information for the current post-date/time and author.
- twentyfifteen_entry_meta()Prints HTML with meta information for the categories, tags.
- twentyfourteen_list_authors()Prints a list of all site contributors who published at least one post.
- twentyfourteen_posted_on()Prints HTML with meta information for the current post-date/time and author.
- twentynineteen_get_the_archive_title()Filters the default archive titles.
- twentynineteen_posted_by()Prints HTML with meta information about theme author.
- twentyseventeen_posted_on()Prints HTML with meta information for the current post-date/time and author.
- twentysixteen_entry_meta()Prints HTML with meta information for the categories, tags.
- twentyten_posted_on()Prints HTML with meta information for the current post-date/time and author.
- twentythirteen_entry_meta()Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
- twentytwelve_entry_meta()Sets up post entry meta.
- twentytwenty_get_post_meta()Retrieves the post meta.
- wp_post_revision_title_expanded()Retrieves formatted date timestamp of a revision (linked to that revisions's page).
- wp_prepare_revisions_for_js()Prepare revisions for JavaScript.
Source code
function get_the_author_meta( $field = '', $user_id = false ) { $original_user_id = $user_id; if ( ! $user_id ) { global $authordata; $user_id = $authordata->ID ?? 0; } else { $authordata = get_userdata( $user_id ); } if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ), true ) ) { $field = 'user_' . $field; } $value = $authordata->$field ?? ''; /** * Filters the value of the requested user metadata. * * The filter name is dynamic and depends on the $field parameter of the function. * * @since 2.8.0 * @since 4.3.0 The `$original_user_id` parameter was added. * * @param string $value The value of the metadata. * @param int $user_id The user ID for the value. * @param int|false $original_user_id The original user ID, as passed to the function. */ return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id );}Changelog
Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
aim, jabber, and yim as valid values for the $field parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/author-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.