/** * Method to emulate the SQL_CALC_FOUND_ROWS placeholder for MySQL. * * This is a kind of tricky play. * 1. remove SQL_CALC_FOUND_ROWS option, and give it to the pdo engine * 2. make another $wpdb instance, and execute the rewritten query * 3. give the returned value (integer: number of the rows) to the original instance variable without LIMIT * * We no longer use SELECT COUNT query, because it returns the inexact values when used with WP_Meta_Query(). * * This kind of statement is required for WordPress to calculate the paging information. * see also WP_Query class in wp-includes/query.php * * @access private */ private function handle_sql_count() { if (!$this->rewrite_calc_found) { return; } global $wpdb; // first strip the code. this is the end of rewriting process $this->_query = str_ireplace('SQL_CALC_FOUND_ROWS', '', $this->_query); // we make the data for next SELECE FOUND_ROWS() statement $unlimited_query = preg_replace('/\\bLIMIT\\s*.*/imsx', '', $this->_query); //$unlimited_query = preg_replace('/\\bGROUP\\s*BY\\s*.*/imsx', '', $unlimited_query); // we no longer use SELECT COUNT query //$unlimited_query = $this->_transform_to_count($unlimited_query); $_wpdb = new PDODB(); $result = $_wpdb->query($unlimited_query); $wpdb->dbh->found_rows_result = $result; $_wpdb = null; }