Query to make a list of subcategories under a category (1 post)

  1. LawrenceCramer
    Posted 4 years ago #

    Hello, I have this SQL and it works great to pull all the posts under a given category - in this case categotu ID 3

    SELECT DISTINCT wp_posts.* 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_status = 'publish'
    AND wp_term_taxonomy.taxonomy = 'category'
    AND wp_term_taxonomy.term_id = 3
    ORDER BY post_date DESC

    Now what I need is a query to pull a list of the subcategories under a given category. I'm a newbie at how the WP database is set up, any suggestions of the SQL I need would be awesome.


Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by LawrenceCramer
  • This topic is not resolved
  • WordPress version: 3.3.2