Welcome to my unobtrusive blog!
By default I blog in english but there is also german content.

Wordpress: getting all posts from a specific category

January 5th, 2009 Posted in english

I wanted to grab all posts from a certain category with a single non-wp-php script and I wrote the following mysql statement to accomplish this task:

SELECT wp_posts.post_title, wp_posts.post_date, wp_posts.post_content, wp_posts.guid 
FROM wp_posts WHERE wp_posts.post_type='post' 
AND wp_posts.post_status='publish' 
AND (
  SELECT wp_term_relationships.object_id 
  FROM wp_term_relationships
  WHERE wp_term_relationships.term_taxonomy_id = (
    SELECT wp_term_taxonomy.term_taxonomy_id 
    FROM wp_term_taxonomy 
    WHERE term_id = 3
    AND taxonomy = 'category'
  )
  AND wp_term_relationships.object_id=wp_posts.id
)
ORDER BY wp_posts.id DESC

Where “3″ is the category id you want the posts from.

follow comments via rss

Post a Comment