Call To A Member Function Get_results On A Non-object Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you fatal error call to a member function get_results() on a non-object in wordpress might have Meta Discuss the workings and policies of this site
Call To A Member Function Get_results() On Null In Wordpress
About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or call to a member function get_results() on a non-object wpdb posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of call to a member function query() on a non-object wordpress 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error in php - Call to a member function get_results() on a non-object up vote -1 down vote favorite 1 I have wordpress blog and I have massive comments under some post. I found recently that
Global $wpdb
some comments are duplicated two or three times. I want to use php code that removes duplicate elements from table wp_comments from mysql database of Wordpress (by opening php file on server). I used this code: get_results("SELECT * FROM ".$wpdb->prefix."_comments" ." ORDER BY comment_post_ID, comment_content"); $prev = NULL; foreach($comments as $comment) { if ($prev && $prev->comment_content == $comment->comment_content && $prev->comment_post_ID == $comment->comment_post_ID ) { $wpdb->query("DELETE FROM ".$wpdb->prefix."_comments WHERE comment_ID == ".$comment->comment_ID); } else $prev = $comment; } ?> and I got this error: *> Fatal error: Call to a member function get_results() on a non-object in .../commentsremoving.php on line 5* UPDATE: Thanks to Sheikh Heera I have now no error message, but my code doesn't work - no duplicated comments were deleted. Any ideas why? php share|improve this question edited Jun 17 '13 at 19:14 asked Jun 17 '13 at 18:44 Jack Bale 112 1 You don't appear to be defining $wpdb anywhe
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us WordPress Development Questions Tags Users Badges Unanswered Ask Question _ WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top $wpdb variable throw this error Call to a member function get_results() on a non-object in up http://stackoverflow.com/questions/17154548/error-in-php-call-to-a-member-function-get-results-on-a-non-object vote 1 down vote favorite I've this error "Call to a member function get_results() on a non-object in" from this code: require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-config.php'); require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-load.php'); if (!$wpdb) { $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); } else { global $wpdb; } function vendorDatails( $param) { if ((substr ($param, 0, 0)) == '#') { substr($param, 1); } $order_ids = $wpdb->get_results( " SELECT DISTINCT vendor_id FROM $wpdb->lqrhxf_pv_commission WHERE order_id = %d ", $param ); http://wordpress.stackexchange.com/questions/167401/wpdb-variable-throw-this-error-call-to-a-member-function-get-results-on-a-non foreach ( $order_ids as $order_id ) { echo $order_id->vendor_id; } } The db parameters are loaded successfully but I've the error on the line above when I use $wpdb variable: $order_ids = $wpdb->get_results( database wpdb errors share|improve this question edited Nov 4 '14 at 15:39 Pieter Goosen 36.9k113687 asked Nov 4 '14 at 15:11 GabrieleU 814 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted This is a PHP variable scope issue, there is no $wpdb defined in your function. Add global $wpdb; before trying to use the $wpdb object. share|improve this answer answered Nov 4 '14 at 15:24 Milo 50k23664 thank you very much, it works! –GabrieleU Nov 4 '14 at 15:30 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged database wpdb errors or ask your own question. asked 1 year ago viewed 2952 times active 1 year ago Related 0Fatal error: Call to a member function query() on a non-object1Get PHP Fatal error on globalized $wpdb: Call to a member function insert() on a non-object- I have
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any http://wordpress.stackexchange.com/questions/162619/call-to-a-member-function-get-results-on-a-non-object-in-wordpress-plugin questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us WordPress Development Questions Tags Users Badges Unanswered Ask Question _ WordPress Development Stack Exchange is a question and answer call to site for WordPress developers and administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Call to a member function get_results() on a non-object in wordpress plugin up vote -1 call to a down vote favorite I am using revolution slider plugin. I got above error while executing one of my front end form. This is my code in that file.. wpdb = $wpdb; } /** * * throw error */ private function throwError($message,$code=-1){ UniteFunctionsRev::throwError($message,$code); } //------------------------------------------------------------ // validate for errors private function checkForErrors($prefix = ""){ if(mysql_error()){ $query = $this->wpdb->last_query; $message = $this->wpdb->last_error; if($prefix) $message = $prefix.' - '.$message.''; if($query) $message .= '
---
Query: ' . $query; $this->throwError($message); } } /** * * insert variables to some table */ public function insert($table,$arrItems){ global $wpdb; $this->wpdb->insert($table, $arrItems); $this->checkForErrors("Insert query error"); $this->lastRowID = $wpdb->insert_id; return($this->lastRowID); } /** * * get last insert id */ public function getLastInsertID(){ global $wpdb; $this->lastRowID = $wpdb->insert_id; return($this->lastRowID); } /** * * delete rows */ public function delete($table,$where){ UniteFunctionsRev::validateNotEmpty($table,"table name"); UniteFunctionsRev::validateNotEmpty($where,"where"); $query = "