mysql - WordPress MySQL query: copy data from a table to another
问题描述
So I'm using a wordpress plugin for a while to add a "Sources" custom field into the end of each post. The thing is this plugin isn't updated for 4 years and I want to get rid of it. But I can't afford to lose the saved sources for each post. I could manually edit these posts one by one, but after looking at the database with the query below I found that theres over 19k posts using this sources plugin.
SELECT *
FROM `wp_postmeta`
WHERE `meta_key` = 'sa_source'
AND `meta_value` <> ''
The sources are stored in wp_postmeta
table, meta_value
column. As I'm not great at SQL, I'm here looking for some help. I need to insert the content from:
wp_postmeta
table,meta_value
column. Wheremeta_value
is not empty
into the end of:
wp_posts
table,post_content
column. Where thepost_id
fromwp_postmeta
is the same asID
fromwp_posts
解决方案
下一个查询可以解决您的问题:
update
wp_posts
join
wp_postmeta on wp_postmeta.post_id = wp_posts.post_id
set
-- add mata_value content to current post_content with one space
post_content = concat(post_content, ' ', meta_value)
where
wp_postmeta.meta_value is not null and wp_postmeta.meta_value <> '';
推荐阅读
- jquery - 如何检查两个图像是否存在然后做其他事情
- android - 如何在 Android Studio 的活动底部制作 Android xml Linerlayout?
- vb.net - 如何使数字不从特定列表中重复
- python - 使用 XGBClassifier 后如何保存填充的缺失数据?
- android - 如何在 Android 上共享具有不同文件名的图像?
- flutter - 值 0 的整数以显示 2 位数字或小数位 - 颤动
- ubuntu - 是否可以使用命令添加前缀值?
- object - TypeError:'int'对象不可下标.....?
- sql-server - 根据与 SQL 中其他表的重合,从同一字段连接行?
- java - 有没有办法将字符串变量放在图像视图中