Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I added a custom field to my wordpress user profile page that asks a user what their favorite browser is. I have the field on the profile.php page, but how can I get this field into my sql database?

What sql script do I need that will insert the user's answer into the table by their corresponding user meta number?

Thanks

share|improve this question
1  
A close look at user meta Qs might help you‌​. –  kaiser May 16 '12 at 1:08

1 Answer 1

To show extra fields in profile, use this hook:

function myplugin_show_profile_extra_fields( $user ) {
    // echo your extra fields here
}
add_action( 'show_user_profile', 'myplugin_show_profile_extra_fields' );
add_action( 'edit_user_profile', 'myplugin_show_profile_extra_fields' );

And to save extra fields use following hook:

function myplugin_save_profile_extra_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }

    update_usermeta( $user_id, 'extra_field', $_POST['my_extra_field'] );
}
add_action( 'personal_options_update', 'myplugin_save_profile_extra_fields' );
add_action( 'edit_user_profile_update', 'myplugin_save_profile_extra_fields' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.