Can not get $wpdb working
-
I am having trouble getting $wpdb to work from a plugin I am developing, or at all for that matter. I am new to WordPress and this is my first site development effort, so please excuse me for my basic questions. I suspect I have not initialized something or loaded something correctly to get it to function, but I’m not sure where.
I started with creating a new website using the twenty seventeen theme on a localhost setup using the latest Bitnami wordpress stack. I then created a child theme to begin making the changes I wanted.
In attempting to access some data from the database, I created the following code inside a new plugin. There is something wrong with the line defining $numberofusers using the $wpdb get_var function, as when it is included in the code wordpress crashes. Everything else in the plugin seems to work correctly. In fact, I don’t seem to be able to use any of the $wpdb functions anywhere (in a plugin, or a basic function, etc.). I added the require statement for wp-load.php to make sure wpdb was loaded.
Thank you for any suggestions that you have.
global $wpdb;
require_once(ABSPATH . ‘wp-load.php’);function mmmp_get_member_info() {
$numberofusers = $wpdb->;get_var( “SELECT COUNT(*) FROM $wpdb->;users;”);
return “The number of rows in the users table are:” .$numberofusers;
}
- The topic ‘Can not get $wpdb working’ is closed to new replies.