$wpdb not being defined in function
-
For some reason the $wpdb object is not being defined in one particular function. I’m working locally here and I have four other functions in the file that are using $wpdb and all are working fine except this one simple delete function where I get the error: Call to a member function query() on a non-object… The following is the function in question:
function delete_gallery( $gallery_id ) { global $wpdb; $sql = "DELETE from galleries WHERE gallery_id = $gallery_id"; $deleted = $wpdb->query( $sql ); }I have a link (delete gallery) on the plugin admin settings page that links to delete-gallery.php that calls the delete function and returns back to the admin page. The contents of that file are:
include 'ga-functions.php'; if (isset($_GET['gallery_id'])) { $gallery_id = $_GET['gallery_id']; delete_gallery($gallery_id); wp_redirect( $_SERVER['HTTP_REFERER'] ); exit(); }If I var_dump on the $wpdb after initializing I get the result of NULL. Anyone have any suggestions on what could be causing this in only one particular function like this.
The topic ‘$wpdb not being defined in function’ is closed to new replies.