我尝试在wordpress Class中获取每个查询的行数,但每次都得到null,以下是
的错误class MyClass{
private $wpdb;
private $query;
public function __construct(){
global $wpdb;
this->wpdb = &$wpdb;
}
public function build_query(){
//dynamic query will be build here, example
$this->query = 'SELECT id,name From my_table';
}
public function get_display_result(){
$res = $this->wpdb->get_results($this->query, ARRAY_A);
return $res;
}
public function get_total_results(){
$res = $this->wpdb->get_results($this->query);
$nr = $res->num_rows;
var_dump($nr);// I get NULL
exit();
return $res;
}
}
答案 0 :(得分:0)
您必须使用$ wpdb来获取行数
$this->wpdb->num_rows;