简体   繁体   中英

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

<?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"

How do i write SQL to update the specific column.

You don't need to write the SQL, wp gives you that function.

If you are doing a one-off to update the DB, then in your phpmyadmin, you just find the record, and edit it manually;

if writing PHP, then you use

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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