Cannot update user display_name field

I’m trying to update user display name when posted through a form.

Here’s what I’m trying:

Read More
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?

Related posts

1 comment

  1. 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 of wp_update_user, as update_user_meta() will create the meta field if it doesn’t exist.

    like

    if ( !empty( $_POST['display_name'] ) ) {    
        update_user_meta( $current_user->ID, 'display_name', esc_attr( $_POST['display_name'] ) );
    }
    

    Then you can use the meta key and value the way you want.

Comments are closed.