admin管理员组文章数量:1335654
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...
);
本文标签: authorDifference between lastname and userlastname
版权声明:本文标题:author - Difference between last_name and user_lastname 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742391615a2466100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论