Question

OK, so I have this question which pertains to posts in wordpress using SQL.

Trying to copy the meta_value below:

meta_key = cb_video_embed_code_post

meta_value = youtube link

To every instance where the meta_key is _feature_video but i wanna only change the meta_value. I hope this makes sense - hard to explain with my limited SQL knowledge

meta_key = _featured_video

meta_value = youtube link

If there is no value for the post then I would like for a _featured_video to be created.

Any help is greatly appreciated!!

Was it helpful?

Solution

Your sql query will be like this (i guess),

$sql = "INSERT INTO `wp_postmeta` (
    `post_id` , `meta_key` , `meta_value`
)
VALUES
(
    '".$POST_ID."',
    '_featured_video', 
    (SELECT P1`meta_value` FROM wp_postmeta as P1 WHERE P1.`meta_key` = 'cb_video_embed_code_post' AND P1.`post_id` = '".$POST_ID."')
)";

In this query $POST_ID will be your various post id...

Hope it will help you.!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top