WordPress Query to fetch the subcategories

<?php
 global $wpdb;
 $cat="2"//Parent category id
 $categoriesData = $wpdb->get_results("SELECT c.*,ct.* FROM
 {$wpdb->prefix}terms as c JOIN  {$wpdb->prefix}term_taxonomy as ct
  ON c.term_id=ct.term_id WHERE ct.taxonomy='category'
  AND ct.parent ='$cat'  ");
?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *