As per documentation, the method get_the_author_meta()
has a $field
argument with the following possible values:
- admin_color
- aim
- comment_shortcuts
- description
- display_name
- first_name
- ID
- jabber
- 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
- yim
I wonder, what is the difference between last_name
and user_lastname
(first_name
and user_firstname
respectively ).
Which property am I supposed to use and what are possible reasons that one might be filled, while at the same time the other is not?
As per documentation, the method get_the_author_meta()
has a $field
argument with the following possible values:
- admin_color
- aim
- comment_shortcuts
- description
- display_name
- first_name
- ID
- jabber
- 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
- yim
I wonder, what is the difference between last_name
and user_lastname
(first_name
and user_firstname
respectively ).
Which property am I supposed to use and what are possible reasons that one might be filled, while at the same time the other is not?
Share Improve this question asked May 28, 2020 at 12:30 user1438038user1438038 1761 silver badge12 bronze badges1 Answer
Reset to default 2Short answer to "Which property am I supposed to use": Use first_name
and last_name
.
Longer answer:
The properties first_name
, user_firstname
, last_name
and user_lastname
are defined in the WP_User
class, and despite the different names (i.e. one with user_
and the other without that prefix):
- Both
first_name
anduser_firstname
use the value of thefirst_name
meta. - Both
last_name
anduser_lastname
use the value of thelast_name
meta.
But user_firstname
and user_lastname
were the property names used in WordPress prior to version 2.0.0 (14 years ago..) — see get_the_author_firstname()
and get_the_author_lastname()
here and here, and that properties are still supported for backward compatibility, but we should just use the ones without the user_
prefix (e.g. first_name
and not user_firstname
).
// Both of these return the same value - the value of the meta named first_name.
var_dump(
get_the_author_meta( 'user_firstname' ), // works
get_the_author_meta( 'first_name' ) // but better
);
// Both of these return the same value - the value of the meta named first_name.
$current_user = wp_get_current_user();
var_dump(
$current_user->user_firstname, // works
$current_user->first_name // but better/shorter...
);