Display user meta by different user role

In your author.php file, get the user metadata via get_user_meta(), then do an if statement of $user->roles == ‘rivenditore’, display the meta data as you desire, and then do an elseif $user->roles == ‘installatori’ statement with what you wish to display for users on other roles. EDIT: Code example as requested: // get author data … Read more

update_user_meta() not working

wp_get_current_user() returns an object. update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ) accepts user_id as first parameter. Use the following code to get user ID from wp_get_current_user() update_user_meta( $user->ID, ‘custom_user_fields’, $userData );

Assign second role to user

If you first fetch a WP_User object with get_userdata(), you should then be able to add your additional role with the add_role() method, like so: $user = get_userdata($user_id); $user->add_role(‘partner’);