最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - Migrating meta_key and meta_value from old theme to new one

programmeradmin2浏览0评论

I've just installed a new theme for my wordpress website. ( Jannah Newspaper Theme, to Bimber )

My website is a platform for posting music videos. Jannah Theme have stored all my embed video posted into my post, into database in wp_postmeta with the meta_key ( tie_video_url ) and the meta_value is showing the youtube video.

But I can't display these videos on my new theme. They do not insert into the post.

Is there an easy trick to inject this data into the new theme with phpmyadmin and to be able to retrieve the video in my published post? I got 11 000 videos on my website. It will take 1 month to do it manually.

Thanks!

I've just installed a new theme for my wordpress website. ( Jannah Newspaper Theme, to Bimber )

My website is a platform for posting music videos. Jannah Theme have stored all my embed video posted into my post, into database in wp_postmeta with the meta_key ( tie_video_url ) and the meta_value is showing the youtube video.

But I can't display these videos on my new theme. They do not insert into the post.

Is there an easy trick to inject this data into the new theme with phpmyadmin and to be able to retrieve the video in my published post? I got 11 000 videos on my website. It will take 1 month to do it manually.

Thanks!

Share Improve this question asked Apr 27, 2020 at 20:21 Samuel BeaudoinSamuel Beaudoin 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You'd have to look more closely at how the old theme displays the postmeta. At this point, you have a few options:

  • Create a child theme for your new theme, and in its PHP file to display single posts, set the child theme up to display the postmeta just like your old theme did. (You will also have to set up postmeta boxes so that new posts can also contain this postmeta.) That way, if you ever want to switch back to your old theme, you won't have to change data.

  • Move the data into the posts themselves, as you've asked. This may be the better option since it should work with any theme, as opposed to preserving the postmeta. The trick will be to figure out how exactly your old theme was displaying the data, and part of this depends on whether you're using the Block Editor or the Classic Editor (or a page builder).

For the second option you'll need to do something like:

Look in the old theme and find how it was displaying the postmeta. You could look at the code itself (likely in single.php)

<?php
if(get_post_meta($post->ID, 'tie_video_url', true)) {
    // The code you're looking for: how the URL gets output
}
?>

or you could look at the front end to see what the end HTML looks like. That'll be the key to proceeding to the next step.

Once you know what the HTML needs to look like, I'm guessing you'll need to use PHP because you won't just be adding the URL to your post content, you'll need the full HTML. However, if the HTML is simple, your MySQL query could look something like this. (Keep in mind you'll need to use your own database's prefix, which might not be "wp_".)

UPDATE wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id SET post_content = CONCAT(wp_postmeta.meta_value, wp_posts.post_content) WHERE wp_postmeta.meta_key = 'tie_video_url');

This simplified query would just take the postmeta value for every post that has the "tie_video_url" meta_key (presumably, the value is the URL) and put it at the beginning of each post's content. Since an URL isn't going to transform into a full embed, again, you'll likely need to work out what HTML needs to wrap around it and use a PHP approach.

发布评论

评论列表(0)

  1. 暂无评论