I have an issue with not being able to call the get_results() function on the $wpdb object inside the Wordpress functions.php file.
Exact error: Call to a member function get_results() on a non-object in [...]
This is my function;
global $wpdb;
function query_students($year){
$wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}usermeta WHERE meta_key ='foobar' AND meta_value = '{$year}'"
)
);
$wpdb->flush();
}
As you can see I've globalised the $wpdb variable, and this function works great in the page template file. I would just prefer it if my functions weren't dotted around the place, and in some kind of centralised file.
Thanks in anticipation! :)