Useful sql query to collect wp posts by category

118 Likes Comment

I have built a blog for years, and now I need to operate it in new style. I’ll create a beta version in localhost, import all posts from current blog to this. I found an useful sql query to collect all my wordpress posts by category

Here is the script:

SELECT post_title,post_content,post_name FROM wp_posts
LEFT JOIN wp_term_relationships ON
(wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy ON
(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
WHERE wp_posts.post_type = 'post'
AND wp_posts.post_status='publish'
AND wp_term_taxonomy.taxonomy = 'category'
AND wp_term_taxonomy.term_id = 1
ORDER BY post_date asc;

Hope this share will help your project too!

You might like

Avatar

About the Author: Toc Xoan

Leave a Reply

Your email address will not be published. Required fields are marked *