I'm trying to manually query the wordpress database to retrieve specific post content for a json feed. In theory I want to return a number of 'Post' objects with each containing a 'tags/categories' array within it of each tag/category.
I'm currently using the following SQL query to retrieve the posts I want, however I think I am missing a relationship between the wp_term_taxonomy table, as well as this returns a unique row per tag/category:
SELECT wp_posts.post_date, wp_posts.post_content, wp_posts.post_title, wp_posts.ID, wp_terms.name
FROM wp_posts
LEFT JOIN wp_term_relationships ON ( wp_term_relationships.object_id = wp_posts.ID )
LEFT JOIN wp_terms ON ( wp_terms.term_id = wp_term_relationships.term_taxonomy_id )
WHERE 1=1
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish')
ORDER BY wp_posts.ID DESC
LIMIT 25
Anyone got any advice on how I can achieve my goal? What I didnt want to do is do one query to get the posts, then iterate through each one and query to get and set the tag/category array - but maybe that's my only option?