0

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?

2

Short 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 and user_firstname use the value of the first_name meta.
  • Both last_name and user_lastname use the value of the last_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...
);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.