Answer the question
In order to leave comments, you need to log in
How to write data from wpdb->get_results() Wordpress to php class property?
Let's say we have a "User" class, a private id property, and a private property that should contain the data retrieved with wpdb->get_results(). I can't figure out how to implement this request inside the class. Basically, I want this:
class User{
private $id;
private $data_from_wbdb_get_results;
publick function __construct($id){
$this->id = $id;
$this->data_from_wbdb_get_results = $wpdb->get_results("SELECT * FROM table WERE id=$this->id");
}
}
Answer the question
In order to leave comments, you need to log in
class User{
private $id;
private $data_from_wbdb_get_results;
publick function __construct($id){
global $wpdb;
$this->id = $id;
$this->data_from_wbdb_get_results = $wpdb->get_results("SELECT * FROM table WERE id=$this->id");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question