admin管理员组文章数量:1123930
Basically I just need to have a table like this:
Post title | Categories |
---|---|
Post 1 | Category 1, Category 2 |
Post 2 | Category 2, Category 2.1 |
... | ... |
From MySQL Query to Retrieve Category from wp_posts I successfully workout this query:
SELECT *
FROM wpd9_posts
LEFT JOIN wpd9_term_relationships ON (wpd9_posts.ID = wpd9_term_relationships.object_id)
LEFT JOIN wpd9_term_taxonomy ON (wpd9_term_relationships.term_taxonomy_id = wpd9_term_taxonomy.term_taxonomy_id)
GROUP BY wpd9_posts.ID
But I don't know how to make it better.
Ideally, I prefer to get it from the API, since I don't have SSH access to my hosting. But using SQL and export to a CSV or JSON file is fine.
Basically I just need to have a table like this:
Post title | Categories |
---|---|
Post 1 | Category 1, Category 2 |
Post 2 | Category 2, Category 2.1 |
... | ... |
From MySQL Query to Retrieve Category from wp_posts I successfully workout this query:
SELECT *
FROM wpd9_posts
LEFT JOIN wpd9_term_relationships ON (wpd9_posts.ID = wpd9_term_relationships.object_id)
LEFT JOIN wpd9_term_taxonomy ON (wpd9_term_relationships.term_taxonomy_id = wpd9_term_taxonomy.term_taxonomy_id)
GROUP BY wpd9_posts.ID
But I don't know how to make it better.
Ideally, I prefer to get it from the API, since I don't have SSH access to my hosting. But using SQL and export to a CSV or JSON file is fine.
Share Improve this question edited Mar 18, 2024 at 12:37 Ooker asked Mar 16, 2024 at 15:07 OokerOoker 3323 silver badges23 bronze badges1 Answer
Reset to default 1If you want to export the data to a CSV or JSON file directly from the SQL query, you can use the MySQL INTO OUTFILE
clause.
SELECT wpd9_posts.post_title, GROUP_CONCAT(wpd9_terms.name) AS categories
FROM wpd9_posts
LEFT JOIN wpd9_term_relationships ON (wpd9_posts.ID = wpd9_term_relationships.object_id)
LEFT JOIN wpd9_term_taxonomy ON (wpd9_term_relationships.term_taxonomy_id = wpd9_term_taxonomy.term_taxonomy_id)
LEFT JOIN wpd9_terms ON (wpd9_term_taxonomy.term_id = wpd9_terms.term_id)
WHERE wpd9_posts.post_type = 'post'
AND wpd9_posts.post_status = 'publish'
GROUP BY wpd9_posts.ID
INTO OUTFILE '/path/to/export/posts_categories.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
本文标签: How to get a list of all posts and their categories
版权声明:本文标题:How to get a list of all posts and their categories? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736610430a1945430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论