Tuesday, 8 October 2019

WP - trying to use `wp_dropdown_users( )` as custom user profile field

I have update to my user profile page to include several select fields with no problem, but I'm not sure how to parse wp_dropdown_users( ) in a way that I can save the selected value to the profile.

Currently I have this as my markup:

<tr>
    <th>
        <label for="user"><?php _e('Select associated user', 'mv'); ?></label>
    </th>
    <td>
        <?phpwp_dropdown_users(); ?><br />
        <span class="description"><?php _e('Please enter the ADOC\'s name.', 'mv'); ?></span>
    </td>
</tr>

and I'm trying to save it like so:

function save_custom_userprofile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) )
    return FALSE;
    update_usermeta( $user_id, 'user', $_POST['user'] );
}
add_action( 'personal_options_update', 'save_custom_userprofile_fields' );
add_action( 'edit_user_profile_update', 'save_custom_userprofile_fields' );

The markup gives me the select, but when I try to save the profile, that select reverts back to the value of the first option.

Any help or guidance on this is, as always, greatly appreciated!



from WP - trying to use `wp_dropdown_users( )` as custom user profile field

No comments:

Post a Comment