Problem with $wpdb->get_var
-
Can anyone PLEASE tell me why the following won’t work?
I’m tearing my hair out here – I’m assuming I have a typo but not sure.
function cat_has_products($id) { global $wpdb; $id = trim($id); $sql = "SELECT term_taxonomy_id from wp_term_taxonomy where term_id = $id;"; $termtaxid = $wpdb->get_var ($wpdb->prepare( $sql) ); echo "ID = $id <br>"; echo "Term id = $termtaxid <br>" ; $catprodcount = $wpdb->get_var ($wpdb->prepare( "select count(object_id) from $wpdb->term_relationships where term_taxonomy_id = $termtaxid;") ); echo "Count is : <br>" . $catprodcount; //return $catprodcount; }Typical output is as follows
ID = 96
Term id =
Count is :where 96 is the value passed to the function.
The topic ‘Problem with $wpdb->get_var’ is closed to new replies.