I've one custom field named as "video" and I want to copy the custom field value to my another custom field named as "theme2035_embed."

I could do it manually, but since I have more than 2500 posts so it's gonna consume a lot of time, it would be nice if someone could tell me a SQL query to do this in a click.

Confusing? let me explain you

There are two custom fields-

  1. video
  2. theme2035_embed

The custom field "video" already has values for each posts (Which is just URL of YouTube video, and is different for each posts)

Now, my new theme uses different custom field for the same function, i.e. "theme2035_embed" what I want to do is that, copy all the individual values of "video" custom field to "theme2035_embed," for each post, counts around 2500.

And later, delete this custom field called as "video."

Update - I figured it out, in case if anyone wants to know the SQL code

update wp_postmeta 
set meta_key = 'theme2035_embed' 
where meta_key = 'video'
  • Note: You could achieve the same effect "internally" to WordPress, without directly manipulating or necessarily even altering the DB via SQL.
    – CK MacLeod
    Jul 20, 2016 at 16:41
  • Sure, if there's an alternate way then please share it in the answers :)
    – Pranjal
    Jul 21, 2016 at 17:14

2 Answers 2


Here's the solution

update wp_postmeta  set meta_key = 'theme2035_embed'  where meta_key = 'video'

Possibly I misunderstood, but what you want is to copy the contained value of the custom field "video", into the custom field "theme2035_embed".

But the suggested query doesn't actually copy any value:

update wp_postmeta set meta_key = 'theme2035_embed' where meta_key = 'video'

... what it actually does is replace the name to the custom field.

The SQL query I suggest is the following, which does literally do what was initially requested:

UPDATE wp_postmeta AS pm1 
INNER JOIN wp_postmeta AS pm2 ON pm1.post_id = pm2.post_id 
SET pm2.meta_value = pm1.meta_value 
WHERE pm1.meta_key = 'video' AND pm2.meta_key = 'theme2035_embed'

This SQL query updates the records in the wp_postmeta table for those that have a meta_key of "video" in pm1 and a meta_key of "theme2035_embed" in pm2 for the same post_id. Then, set the meta_value value of pm2 equal to the meta_value value of pm1.

Sorry por la demora... ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.