嘿,我正在尝试更新用户元,但它没有更新
$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( $user_id, 'date_of_birth', $dobs );
wordpress 使用第四个参数仅更新先前值等于第四个参数值的字段
因此,wordpress 正在寻找该用户先前值为 true 的 date_of_birth
更多info
关于php - WordPress 更新元不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47299946/