I’m trying to update user display name when posted through a form.
Here’s what I’m trying:
if ( !empty( $_POST['display_name'] ) ){
//var_dump($_POST['display_name'] );
wp_update_user( array ( 'ID' => $current_user->ID, 'display_name' => esc_attr( $_POST['display_name'] ) ) );
}
I can see that the display name is posted correctly, but it just does not update it. I can update the user url successfully but not the display_name and first_name/ last_name.
Is there any other way to update these fields?
This is because there is no meta key named display_name, so if you want to update a single meta value better use
update_user_meta
instead ofwp_update_user
, as update_user_meta() will create the meta field if it doesn’t exist.like
Then you can use the meta key and value the way you want.