所以,我使用以下代码来允许人们将步兵或车辆添加到他们的个人资料中
function after_submission($form) {
$user = wp_get_current_user();
$user_id = $user->ID;
$infantry = $form[1];
$vehicle = $form[2];
update_user_meta( $user_id, 'infantry', $infantry);
update_user_meta( $user_id, 'vehicle', $vehicle);
我的问题是步兵&车辆正在更新,而不是增加。
有什么建议吗?
答案 0 :(得分:0)
尝试这样:
$user = wp_get_current_user();
$user_id = $user->ID;
$infantry = $form[1];
$vehicle = $form[2];
$oldInfantry = get_user_meta( $user_id, 'infantry', true);
$oldVehicle = get_user_meta( $user_id, 'vehicle', true);
update_user_meta( $user_id, 'infantry', $infantry+$oldInfantry);
update_user_meta( $user_id, 'vehicle', $vehicle+$oldVehicle);
答案 1 :(得分:0)
使用类似的东西:
$oldInfantry = $user->infantry;
$oldVehicle = $user->vehicle;
$extraInfantry = $form[1];
$extraVehicle = $form[2];
$newInfantry = $oldInfantry + $extraInfantry ;
$newVehicle = $oldVehicle + $extraVehicle;
update_user_meta( $user_id, 'infantry', $newInfantry);
update_user_meta( $user_id, 'vehicle', $newVehicle);