i trying add custom user profile fields wordpress users.
i have added following code functions.php reason data entered not saving...
//** custom user meta **// add_action( 'show_user_profile', 'my_show_extra_profile_fields' ); add_action( 'edit_user_profile', 'my_show_extra_profile_fields' ); function my_show_extra_profile_fields( $user ) { ?> <h3>extra profile information</h3> <table class="form-table"> <tr> <th><label for="club">club support</label></th> <td> <input type="text" name="club" id="club" value="<?php echo esc_attr( get_the_author_meta( 'club', $user->id ) ); ?>" class="regular-text" /><br /> </td> </tr> </table> <?php } add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { update_usermeta( $user_id, 'club', sanitize_text_field( $_post['club']) ); }
any ideas why data isn't sticking ?
there easier , proper way create new profile fields in wordpress. based on code above, try dropping code below on functions.php
file on theme:
function my_show_extra_profile_fields { $user_contact_method['club'] = 'club support'; return $user_contact_method; } add_filter( 'user_contactmethods', 'my_show_extra_profile_fields' );
this automatically create new fields on profile page , accordingly save them data base custom fields (meta) user.
you can display info on theme using the_author_meta('club');