SQL query to extract all WordPress posts with categories
-
I need to extract all posts from my WordPress DB along with the associated categories and not sure how to write this query.
SELECT post_title, wpr.object_id, wp_terms.name FROM wp_terms INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id INNER JOIN wp_term_relationships wpr ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id INNER JOIN wp_posts ON ID = wpr.object_id WHERE taxonomy = 'category' AND post_type = 'post
The problem I have with this query is that it returns 1,553 records, when I know it should only be returning 1,343.
I am assuming this happens because there might be multiple categories per post, so what I would appreciate, is how to show all the posts, of type = post and show each category in its own column.
Lastly, I don’t want to use the WP API because I need to export all this information as a CSV, so that I can re-import it in a products table for WP-eCommerce.
Many thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘SQL query to extract all WordPress posts with categories’ is closed to new replies.