wordpress query num_rows不会返回值

时间:2014-06-01 11:32:50

标签: database wordpress mysql-num-rows

我尝试在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;

        }

    }

1 个答案:

答案 0 :(得分:0)

您必须使用$ wpdb来获取行数

$this->wpdb->num_rows;