我已将此代码段添加到函数中。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\'] );
}
现在我在用户配置文件中看到了章节下拉列表。但当我更改用户章节时,它不会被保存。例如:如果我选择
MPF Pune East 然后按按钮更新配置文件,然后我再次看到
MPF Pune Central 默认情况下。单击“更新配置文件”按钮时,似乎无法保存。我们是否必须采取其他措施才能挽救它?
SO网友:Aftab
我看得出来
$topselected= get_the_author_meta( \'user_top\', $user->ID );
,
您使用的是“user_top“作为meta\\u键,但在更新时使用”user_chapter“”
update_usermeta( $user_id, \'user_chapters\', $_POST[\'user_chapters\'] );
无论什么
name
您正在提供
<select name="user_top" id="user_top">
, 应在中使用
$_POST[\'\']
所以你在这里使用“user_top“作为您选择的名称,因此$_POST[\'user_top\']