I was writing a WordPress plugin and encountered an error saying:
Fatal error: Call to a member function get_var() on a non-object in ……. on line ….
The code was clear and short and didn’t have any such bugs to cause fatal errors.
However, there was something missing which caused this error.
To solve this error, simply add this line of code above / in between your code where necessary:
global $wpdb;
This shouldn’t trigger the Fatal error: Call to a member function get_var() on a non-object in … on line … again.