I want to reuse the same MySQL query, so thought wrapping it in PHP function might help. I did it as follows:
function fetch_from_db($criteria) {
global $wpdb;
$qvar = $wpdb->get_results("select * from $wpdb->terms, $wpdb->term_taxonomy where $wpdb->terms.term_id = $wpdb->term_taxonomy.term_taxonomy_id and $wpdb->term_taxonomy.taxonomy = %s", $criteria);
return $qvar;
}
$get_two_wheeler_make = fetch_from_db('2-wheeler-make');
but things are not working and it is returning null. How do I make it work? What is wrong in the code?
array(0) {}$wpdb->get_results("select * from" . $wpdb->terms, $wpdb->term_taxonomy . "where" . $wpdb->terms.term_id . "=" . $wpdb->term_taxonomy.term_taxonomy_id and $wpdb->term_taxonomy.taxonomy . "=" . $criteria);anddoes not need double quotes. I geave spaces everywhere else. Now I am getting result back but it is fetching all the result in the table. It doesnt consider $criteria at all that is passed to the function