WordPress Query to fetch the Categories

global $wpdb;
$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'  ");
foreach($categoriesData as $key=>$category) {
echo $category->name;
}
Share

Leave a Reply

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