wordpress 更新元不工作
wordpress update meta not working
嘿,我正在尝试更新用户元但它没有更新
$dobs=$_REQUEST['day'].'_'.$_REQUEST['month'].'_'.$_REQUEST['year'];
$gender=$_REQUEST['gender'];
$country=$_REQUEST['country'];
$state=$_REQUEST['state'];
$city=$_REQUEST['city'];
update_user_meta( $user_id, 'date_of_birth', $dobs, true );
update_user_meta((int) $user_id, 'gender', (int) $gender, true );
update_user_meta( $user_id, 'country', $country, true );
update_user_meta( $user_id, 'state', $state, true );
update_user_meta( $user_id, 'city', $city, true );
我在这里尝试了像 (int) (string) 这样的类型转换,有趣的部分是插入工作正常不知道数据库结构是否有错误。
update_user_meta() - Update user meta field based on user ID. It has only three arguments in general where the 4th is optional. The 4th parameter is the $prev_value
which in default will be the '' values alone. Hence the 4th parameter will be checking whether the meta_key
updated has the previous values to it.
例如:
<?php
$user_id = 1;
$website_url = 'http://wordpress.org';
update_user_meta($user_id, 'user_url', $website_url, TRUE);
// The above statement will update the user_meta table corresponding to the user_id=1
?>
注意:前 3 个参数是必需的。没有它是行不通的。
请确保 update_user_meta() 中的 'second value' 应该存在于数据库 table 中。
根据问题作者情景:
update_user_meta( $user_id, 'date_of_birth', $dobs, true );
它必须具有所有 3 个参数,即 $user_id
、date_of_birth
和 $dobs
。
您需要删除 update_user_meta
的第 4 个参数
update_user_meta( $user_id, 'date_of_birth', $dobs );
wordpress 使用第 4 个参数仅更新先前值等于第 4 个参数值的字段
所以 wordpress 正在寻找 date_of_birth
具有该用户的先前值
更多info
嘿,我正在尝试更新用户元但它没有更新
$dobs=$_REQUEST['day'].'_'.$_REQUEST['month'].'_'.$_REQUEST['year'];
$gender=$_REQUEST['gender'];
$country=$_REQUEST['country'];
$state=$_REQUEST['state'];
$city=$_REQUEST['city'];
update_user_meta( $user_id, 'date_of_birth', $dobs, true );
update_user_meta((int) $user_id, 'gender', (int) $gender, true );
update_user_meta( $user_id, 'country', $country, true );
update_user_meta( $user_id, 'state', $state, true );
update_user_meta( $user_id, 'city', $city, true );
我在这里尝试了像 (int) (string) 这样的类型转换,有趣的部分是插入工作正常不知道数据库结构是否有错误。
update_user_meta() - Update user meta field based on user ID. It has only three arguments in general where the 4th is optional. The 4th parameter is the
$prev_value
which in default will be the '' values alone. Hence the 4th parameter will be checking whether themeta_key
updated has the previous values to it.
例如:
<?php
$user_id = 1;
$website_url = 'http://wordpress.org';
update_user_meta($user_id, 'user_url', $website_url, TRUE);
// The above statement will update the user_meta table corresponding to the user_id=1
?>
注意:前 3 个参数是必需的。没有它是行不通的。
请确保 update_user_meta() 中的 'second value' 应该存在于数据库 table 中。
根据问题作者情景:
update_user_meta( $user_id, 'date_of_birth', $dobs, true );
它必须具有所有 3 个参数,即 $user_id
、date_of_birth
和 $dobs
。
您需要删除 update_user_meta
update_user_meta( $user_id, 'date_of_birth', $dobs );
wordpress 使用第 4 个参数仅更新先前值等于第 4 个参数值的字段
所以 wordpress 正在寻找 date_of_birth
具有该用户的先前值
更多info