增加值而不是使用WordPress更新user

编程入门 行业动态 更新时间:2024-10-24 20:16:35
增加值而不是使用WordPress更新user_meta(Increase value instead of updating user_meta with WordPress)

所以,我使用以下代码来允许人们将步兵或车辆添加到他们的个人资料中

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);

我的问题是步兵和车辆正在更新,而不是增加。

有什么建议么?

So, I'm using the following code to allow people to add infantry or vehicle to their profile

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);

My problem is that infantry & vehicle is getting updated, rather than increased.

Any suggestions?

最满意答案

试试这样:

$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);

try like this:

$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);

更多推荐

本文发布于:2023-07-28 19:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308185.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:增加值   而不是   user   WordPress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!