check for duplicate user meta data before updating
I have added the ability for a social security number to be added for users. This field can be edited on the individual users screen but the data is saved to the usermeta table. When editing a new user, I want to check if that number is being used somewhere else for another user as duplicates should not be allowed.
My initial code is:
function save_cust_user_profile_fields( $user_id ) {
if ( isset($_POST['social_number']) ) {
update_user_meta( $user_id, 'social_number', intval($_POST['social_number']));
}
}
add_action( 'personal_options_update', 'save_cust_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_cust_user_profile_fields' );
But this obviously allows duplicates which it shouldn't.
Topic user-meta users custom-field Wordpress
Category Web