我有一个带有以下字段的表单:姓名、地址、班级和年龄。当我输入一个新注册表时,表中的名称字段会更新wp_users
.
保存ID后,我将尝试更新用户元字段,如地址,但这不会发生。下面是我的PHP代码。请帮助我:
<?php
$userdata = array(
\'user_login\' => $_POST[\'usname\'],
\'user_pass\' => $_POST[\'passw\'] // When creating an user, `user_pass` is expected.
);
$user_id = wp_insert_user( $userdata ) ;
//On success
if ( ! is_wp_error( $user_id ) ) {
echo "User created : ". $user_id;
}
if(isset($_REQUEST[\'r_submit\']))
{
$id = $_GET[\'ID\'];
$user_id = $id;
$meta_key = "address";
$meta_value = $_REQUEST[\'address\'];
update_user_meta( $user_id, $meta_key, $meta_value );
}
?>
SO网友:user118438
按以下方式更改代码,我得到了答案:
$userdata = array(
\'user_login\' => $_POST[\'usname\'],
\'user_pass\' => $_POST[\'passw\'] // When creating an user, `user_pass` is expected.
);
$user_id = wp_insert_user( $userdata ) ;
update_user_meta( $user_id, \'address\', $_REQUEST[\'address\'] );
update_user_meta( $user_id, \'age\', $_REQUEST[\'age\']);
update_user_meta( $user_id, \'class\', $_REQUEST[\'class\']);
//On success
if ( ! is_wp_error( $user_id ) ) {
echo "User created : ". $user_id;
}