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?

0

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.

  • 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 Oct 28 '13 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? – Maruti Mohanty Oct 28 '13 at 10:48

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.