简体   繁体   English

如何更新WordPress wp_usermeta?

[英]How to update WordPress wp_usermeta?

I need to update a single column in wordpress wp_usermeta .I have gone through the web and I found these codes 我需要更新wordpress wp_usermeta的单个列。我已经遍历网络,发现了这些代码

<?php update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ); ?>

Here user_id=1, meta_key=first_name, meta_value="Smith", $prev_value="benny" 在这里,user_id = 1,meta_key = first_name,meta_value =“ Smith”,$ prev_value =“ benny”

How do i write SQL to update the specific column. 如何编写SQL更新特定列。

You don't need to write the SQL, wp gives you that function. 您无需编写SQL,wp为您提供了该功能。

If you are doing a one-off to update the DB, then in your phpmyadmin, you just find the record, and edit it manually; 如果您要一次性更新数据库,则只需在phpmyadmin中找到记录,然后手动进行编辑即可;

if writing PHP, then you use 如果编写PHP,则使用

update_user_meta( $user_id, $meta_key, $meta_value, $prev_value )

ie update_user_meta( 1, 'first_name', 'Smith', 'benny' ) 即update_user_meta(1,'first_name','Smith','benny')

Use below code to update user meta value if it match old meta value 如果与旧元值匹配,请使用以下代码更新用户元值

$user_id = 1;
$meta_key = 'first_name';
$new_value = 'Smith';
$prev_value = 'benny';


update_user_meta( $user_id, $meta_key, $new_value, $prev_value );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM