道歉,这是一个duplicate of entry of this post,但我发现我没有在那里得到正确的答案,不知道如何要求将其移至SO?我需要使用CSV格式的SQL查询导出所有WordPress帖子和相关的元信息.我设法只导出帖子,但意识到元信息...
道歉,这是一个duplicate of entry of this post,但我发现我没有在那里得到正确的答案,不知道如何要求将其移至SO?
我需要使用CSV格式的SQL查询导出所有WordPress帖子和相关的元信息.我设法只导出帖子,但意识到元信息在另一个表中.
有人可以告诉我,我该怎么做呢?
谢谢!
编辑:我已经尝试了一些插件,其中没有一个适用于这个特定的场景.我确实需要处理查询本身.谢谢
编辑:CSV文件的最终结果应该是这样的.在一行中,这些是我最终会得到的列. (我将删除CSV中的其他列,我只是在这里提供缩短版本)
post_content | post_title | **meta_key** | *meta_value* | **meta_key** | *meta_value* | **meta_key** | *meta_value* | **meta_key** | *meta_value* | **meta_key** | *meta_value*
因此,每行一个帖子,同一行中的元信息.
编辑:有了S-ha-dum,我已经设法得到了一些方法,但我有大约12个meta_value> meta_key值要退出数据库,所以我需要帮助来编写查询的其余部分
SELECT *,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Publisher' AND wp_postmeta.post_id = wp_posts.ID) as Publisher FROM wp_posts
解决方法:
一位朋友最终设法帮我解决了我的问题.这是他将包含元信息的所有帖子导出到CSV文件的最终SQL查询.
SELECT DISTINCT
post_title
, post_content
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Asking Price (US\$)' AND wp_postmeta.post_id = wp_posts.ID) as "Asking Price (US\$)"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Asking Price (ZAR)' AND wp_postmeta.post_id = wp_posts.ID) as "Asking Price (ZAR)"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Author' AND wp_postmeta.post_id = wp_posts.ID) as Author
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Binding' AND wp_postmeta.post_id = wp_posts.ID) as Binding
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Book Condition' AND wp_postmeta.post_id = wp_posts.ID) as "Book Condition"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Book Number' AND wp_postmeta.post_id = wp_posts.ID) as "Book Number"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Book Type' AND wp_postmeta.post_id = wp_posts.ID) as "Book Type"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Edition' AND wp_postmeta.post_id = wp_posts.ID) as Edition
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Illustrator' AND wp_postmeta.post_id = wp_posts.ID) as Illustrator
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Inscription' AND wp_postmeta.post_id = wp_posts.ID) as Inscription
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'ISBN' AND wp_postmeta.post_id = wp_posts.ID) as ISBN
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Jacket Condition' AND wp_postmeta.post_id = wp_posts.ID) as "Jacket Condition"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Location' AND wp_postmeta.post_id = wp_posts.ID) as Location
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Published Place' AND wp_postmeta.post_id = wp_posts.ID) as "Published Place"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Published Year' AND wp_postmeta.post_id = wp_posts.ID) as "Published Year"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Publisher' AND wp_postmeta.post_id = wp_posts.ID) as Publisher
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Size' AND wp_postmeta.post_id = wp_posts.ID) as Size
FROM wp_posts
WHERE post_type = 'post'
ORDER BY
post_title
, post_content
谢谢各位的意见!
本文标题为:mysql – 使用SQL Query以CSV格式导出WordPress帖子和元信息
- PbootCMS网站标题描述等标签限制字数的办法 2023-07-08
- dedecms织梦列表页标题增加页码的方法 2022-07-22
- 织梦dedecms最全的清除文档的sql语句 2022-06-24
- 怎么安装使用PbootCMS网站模板 2023-07-08
- pbootcms去除ueditor编辑器图片自动添加的title和alt属性 2023-07-08
- 织梦dedecms点击数统计控制(刷新页面不新增点击数) 2022-07-20
- PbootCMS伪静态配置教程以及各web容器配置规则 2023-07-08
- 织梦采集标题不完整的解决方法,修改标题长度 2022-07-14
- pbootcms文章插入图片不固定宽高的办法 2023-07-08
- 织梦DedeCMS如何实现文章列表隔行换色变样式 2023-07-08