How to copy meta_value of wp_usermeta to the same table however different meta_key?

Sapien Elva

I am trying to copy the first name to the display name. I created a temporary table call wp_tmp_usermeta. And did a join. However, no rows affected. Whhyyyyyyyy?

Error Message: 0 rows affected. (Query took 0.0213 seconds.)

UPDATE
    `wp_usermeta`
JOIN (SELECT `meta_value`,`user_id` FROM `wp_tmp_usermeta` WHERE `wp_tmp_usermeta`.`meta_key` = 'first_name') newtable ON newtable.`user_id` = `wp_usermeta`.`user_id`
SET
    `wp_usermeta`.meta_value = newtable.meta_value
WHERE
    `wp_usermeta`.meta_key = 'nickname'  ;

Desired result is to copy the value of first_name to nickname

sticky bit

If you want to copy (i.e. really duplicate the rows) the first name but keyed as nickname, you don't need a temporary table and no UPDATE. You want an INSERT ... SELECT.

INSERT INTO wp_usermeta
            (meta_key,
             meta_value,
             user_id)
            SELECT 'nickname',
                   meta_value,
                   user_id
                   FROM wp_usermeta
                   WHERE meta_key = 'first_name';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to modify the (meta_value) in the (wp_usermeta table) with Wordpress function?

CONCAT(meta_key,meta_value) into different columns from wp_postmeta table

Construct MySQL query ( meta_key/meta_value table)

Update table wp_postmeta column meta_value where meta_key column equals certain value

WP SQL add meta_key with an empty meta_value to all users

How to count how many times a meta_value appears in a column by certain meta_key?

How to display meta_value only once if the value is the same

How to update meta_value to wp_postmeta

How do I display my meta_key value in my wp_query() loop

How to build table from two tables, one with useless unique identifier (WordPress wp_usermeta table)

Filter by custom field 'meta_key', 'meta_value' for archive

SQL query to retrieve users combining two meta keys and values from wp_usermeta

SQL - transpose a column and grab the value from the adiacent column - wordpress table wp_usermeta

how to make sorting by meta_key in wordpress

Get Meta_Value from WP database

WP REST API orderby meta_value

How to select all meta values of certain meta_key's?

How to update user meta for multiple meta_key in wordpress

WordPress how to use multiple meta_query and meta_key

Getting 'meta_value' when searching for matching 'post_id' and 'meta_key', 'meta_value' combo

Specific SQL query (multiple meta_value / same row)

custom wp_query where meta_key is variable or not needed

Get all products with specific meta_key whose meta_value is equal in WooCommerce

Update product price if specific meta_key contains a specific meta_value

Group similar meta_key values and create result set with meta_value data

Sql query to exclude meta_value where meta_key = x on SUM for WooCommerce

Retrieve Post by Custom Query String identified by meta_key and meta_value in Wordpress

SQL query with meta_key,meta_value and have 2 conditions

How to insert same data (or copy) in a same table for different record in postgres

TOP Ranking

HotTag

Archive