Support » Fixing WordPress » Query to make a list of subcategories under a category

  • 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.

    Thanks!

  • The topic ‘Query to make a list of subcategories under a category’ is closed to new replies.