Why does this code fail to display the category name ‘Apples’ using the current WordPress taxonomy system? The Category names are stored in the $wpdb->terms table (wp_terms).
<?php $ra_category_id = 3; $ra_category = $wpdb->get_results('SELECT name FROM $wpdb->terms WHERE term_id = '3''); $ra_category_name = $ra_category->name; ?> <h3>Category: <?php echo $ra_category_name; ?></h3>
The table rows are
term_id name slug term_group 1 Uncategorized uncategorized 0 2 Blogroll blogroll 0 3 Apples apples 0 4 Bananas bananas 0
$ra_category is the following array:
So what you want is:
When dealing with query results, always check the whole result with a
var_dump(), it helps.(note that you’re also using
$ra_category_idbut then hardcoding the value ‘3’ in your query)