【发布时间】:2019-08-14 03:56:53
【问题描述】:
我正在尝试添加输入类型并将其从文本更改为单选按钮,以在我的 wordpress 主题用户配置文件设置中使用,例如性别:男性女性,但无法在代码中完成此操作。不知道怎么改。
尝试使用下面给出的 w3schools 的一些代码,但这也不起作用。
试过收音机类型,但不起作用
<label><?php _e( 'gender', 'themer' ); ?></label>
<input type="radio" name="user_new_field" <?php if (isset($new_field) && $new_field=="female") echo "checked";?> value="female">Female
<input type="radio" name="user_new_field" <?php if (isset($new_field) && $new_field=="male") echo "checked";?> value="male">Male
</div>
我必须将代码更改为无线电类型,将在 wordpress functions.php 中使用它们
add_action( 'themer_after_user_profile_registration_fields_action', 'wpt_show_user_profile_custom_inputs' );
function wpt_show_user_profile_custom_inputs( $uid ) {
$user_new_field = get_user_meta( $uid, 'user_new_field', true );
$new_field = empty( $_POST['user_new_field'] ) ? $user_new_field : stripslashes( $_POST['user_new_field'] ); ?>
<div class="field">
<label><?php _e( 'gender', 'themer' ); ?></label>
<input type="text" value="<?php echo $new_field; ?>" name="user_new_field" size="40" placeholder="<?php echo _x( 'My New Field Placeholder', 'Placeholder for: New field', 'themer' ); ?>" />
</div>
<?php }
// Save the field value from user settings page
add_action( 'themer_user_profile_extra_fields_update', 'wpt_save_user_profile_custom_inputs' );
function wpt_save_user_profile_custom_inputs( $uid ) {
if ( isset( $_POST['save-info'] ) ) {
if ( isset( $_POST['user_new_field'] ) ) {
update_user_meta( $uid, 'user_new_field', $_POST['user_new_field'] );
}
}
}
【问题讨论】:
-
您使用的是哪个主题?
标签: php html wordpress custom-fields