How to update WordPress wp_usermeta?

2019-09-19 15:30发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-09-19 16:10

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 );
查看更多
Evening l夕情丶
3楼-- · 2019-09-19 16:18

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

查看更多
登录 后发表回答