1

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?

1 Answer 1

-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.

2
  • 1
    Thanks for your reply, however even this does not work. Its very strange because I can update the user_url and a few other fields with wp_update_user. However I cannot update display_name, even with the above answer.
    – jay
    Commented Oct 28, 2013 at 10:44
  • Can you check if the conditions gets true or not, if true then try and check if you are getting the values for $current_user->ID and $_POST['display_name'] and did you use update_user_meta? Commented Oct 28, 2013 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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