Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend wpdb in other class - when use get_results for select gives me null

Tags:

wordpress

I've added custom plugin (created by me) in WP in that plugin I have Class named BaseModel, which extends wpdb.

The problem here is everytime when I try to run query I get false or null or empty array as result.

class BaseModel extends wpdb{

public function __construct(){
    parent::__construct(DB_HOST, DB_USER, DB_PASS, DB_NAME);
}

function get_destinations($limit, $order){
    $query = "SELECT * FROM wp_relations";

    $result = $this->get_results($query, ARRAY_A);
    var_dump($result); 
}

function get_total_destinations(){
}}

Can some one tell me what is wrong?

Thanks.

like image 702
James Avatar asked Dec 17 '12 00:12

James


1 Answers

Actually it is not a full OOP solution but I solve this by adding global $wpdb into my functions.

class BaseModel {


function get_destinations($limit, $order){
    global $wpdb;
    $query = "SELECT * FROM wp_relations";

    $result = $wpdb->get_results($query, ARRAY_A);
    var_dump($result); 
}

function get_total_destinations(){
}}

I hope you will find this helpful.

like image 144
James Avatar answered Sep 30 '22 18:09

James