I have been trying to get this to work for awhile now and I cannot seem to get any farther on my own. It seems to work fine as a normal SQL query but not within the WP framework using prepare(). Basically I am trying to insert a PHP variable within the SQL query but instead of returning the value I SELECTed, the function returns the value of the variable.
I have searched for others having the same problem but most of them are dealing with problems with LIKE and the % wildcard. I cannot figure out what my problem is.
I am using a bbPress variable which is the forum id.
Any help would be appreciated.
global $wpdb; $countquery = $wpdb->get_var($wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_bbp_forum_subforum_count' AND post_id=%d", bbp_forum_id())); echo $countquery;