MySQL code fails to display category name (WordPress database)

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


$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:

array(1) {
  object(stdClass)(1) {
    string(8) "Apples"

So what you want is:

$ra_category_name = $ra_category[0]->name;

When dealing with query results, always check the whole result with a var_dump(), it helps.

(note that you're also using $ra_category_id but then hardcoding the value "3" in your query)

Need Your Help

How to caching images in GWT with no-cache property in header?

javascript gwt caching web client-side

How to caching images in GWT with no-cache property in header ? I can't make changes in server and i need cache images in GWT side .

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.