道歉,这是一个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帖子和元信息
基础教程推荐
- dedecms根据来访IP区域自动跳转对应页面的方法 2022-07-21
- dedecms织梦无需登录注册可下单购买的修改 2022-11-04
- pbootcms网站自动清理runtime缓存方法 2023-07-09
- 织梦DedeCMS搜索指定多个栏目文档的办法 2022-11-11
- 织梦dedecms如何在dede:sql中使用[field:global.autoindex/] 2022-08-27
- dedecms织梦cms常用判断语句汇总 2022-06-24
- pbootcms二次开发必须要了解的后台目录结构 2023-07-09
- 织梦dedecms调用当前栏目文章数的方法 2022-11-08
- dedecms织梦全局变量调用方法总结 2023-07-08
- PbootCMS网站标题描述等标签限制字数的办法 2023-07-08