I've added this code snippet to my functions.php
//hooks
add_action( 'show_user_profile', 'Add_user_fields' );
add_action( 'edit_user_profile', 'Add_user_fields' );
function Add_user_fields( $user ) { ?>
<h3 class="sizeShapeH3">Select Chapters</h3>
<table class="form-table">
<tr>
<th><label for="dropdown" >MPF Chapters </label></th>
<td>
<?php
$topselected= get_the_author_meta( 'user_top', $user->ID );
?>
<select name="user_top" id="user_top">
<option value="MPF Pune Central:" <?php echo ($topselected == "MPF Pune Central:")? 'selected="selected"' : '' ?>>MPF Pune Central:</option>
<option value="MPF Pune East:" <?php echo ($topselected == "MPF Pune East:")? 'selected="selected"' : '' ?>>MPF Pune East:</option>
<option value="MPF Pune West:" <?php echo ($topselected == "MPF Pune West:")? 'selected="selected"' : '' ?>>MPF Pune West:</option>
<option value="MPF Pune South:" <?php echo ($topselected == "MPF Pune South:")? 'selected="selected"' : '' ?>>MPF Pune South:</option>
<option value="MPF PCMC:" <?php echo ($topselected == "MPF PCMC:")? 'selected="selected"' : '' ?>>MPF PCMC:</option>
</select>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_user_fields' );
add_action( 'edit_user_profile_update', 'save_user_fields' );
function save_user_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
//save top
update_usermeta( $user_id, 'user_chapters', $_POST['user_chapters'] );
}
Now I see the chapter dropdown list at the user profile. but it is not saved when I change the user chapter. Eg: from the above list if I select MPF Pune East and press the button Update Profile then again I see MPF Pune Central as default. Seems it is not get saved when we click Update Profile button. do we have to something else to get it saved?