I have this code that creates a field in the user record, but it is not showing up in the user search. Apparently it seems to be saving or what is entering in the field, but I would like to be able to use it by typing only what was filled in the field. can anybody help me?
function show_my_fields( $user ) {
$fetched_field = get_user_meta( $user->ID, 'my_field', true ); ?>
<tr class="form-field">
<th scope="row"><label for="my-field"><?php _e('Field Name') ?> </label></th>
<td><input name="my_field" type="text" id="my-field" value="<?php echo esc_attr($fetched_field); ?>" /></td>
</tr>
<?php
}
add_action( 'show_user_profile', 'show_my_fields' ); //show in my profile.php page
add_action( 'edit_user_profile', 'show_my_fields' ); //show in my profile.php page
//add_action( 'user_new_form_tag', 'show_my_fields' ); //to add the fields before the user-new.php form
add_action( 'user_new_form', 'show_my_fields' ); //to add the fields after the user-new.php form
/**
* Saving my form fields
*/
function save_my_form_fields( $user_id ) {
update_user_meta( $user_id, 'my_field', $_POST['my_field'] );
}
add_action( 'personal_options_update', 'save_my_form_fields' ); //for profile page update
add_action( 'edit_user_profile_update', 'save_my_form_fields' ); //for profile page update
add_action( 'user_register', 'save_my_form_fields' ); //for user-new.php page new user addition