Useful sql query to collect wp posts by category

75 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

About the Author: Toc Xoan

This guy likes taking photos, hunting cheap tours, exploring the unique culture of every cities of Vietnam. Contact: [email protected]. I've created a dogecoin wallet to receive blog funding: DE6F5FisSCy7yz5rpHY1ChMSGYnDMpFZ1Q

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.