Changeset 34544
- Timestamp:
- 09/25/2015 02:34:20 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r34542 r34544 97 97 98 98 /** 99 * The amount of found comments for the current query. 100 * 101 * @since 4.4.0 102 * @access public 103 * @var int 104 */ 105 public $found_comments = 0; 106 107 /** 108 * The number of pages. 109 * 110 * @since 4.4.0 111 * @access public 112 * @var int 113 */ 114 public $max_num_pages = 0; 115 116 /** 99 117 * Make private/protected methods readable for backwards compatibility. 100 118 * … … 120 138 * @since 4.2.0 121 139 * @since 4.4.0 `$parent__in` and `$parent__not_in` were added. 122 * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache` wasadded.140 * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache` and `$no_found_rows` were added. 123 141 * @access public 124 142 * … … 149 167 * @type int $offset Number of comments to offset the query. Used to build LIMIT clause. 150 168 * Default 0. 169 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. 170 * Default: true. 151 171 * @type string|array $orderby Comment status or array of statuses. To use 'meta_value' or 152 172 * 'meta_value_num', `$meta_key` must also be defined. To sort by … … 204 224 'number' => '', 205 225 'offset' => '', 226 'no_found_rows' => true, 206 227 'orderby' => '', 207 228 'order' => 'DESC', … … 331 352 $comment_ids = array_map( 'intval', $comment_ids ); 332 353 354 $this->comment_count = count( $this->comments ); 355 356 if ( $comment_ids && $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 357 /** 358 * Filter the query used to retrieve found comment count. 359 * 360 * @since 4.4.0 361 * 362 * @param string $found_comments_query SQL query. Default 'SELECT FOUND_ROWS()'. 363 * @param WP_Comment_Query $comment_query The `WP_Comment_Query` instance. 364 */ 365 $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this ); 366 $this->found_comments = (int) $wpdb->get_var( $found_comments_query ); 367 368 $this->max_num_pages = ceil( $this->found_comments / $this->query_vars['number'] ); 369 } 370 333 371 if ( 'ids' == $this->query_vars['fields'] ) { 334 372 $this->comments = $comment_ids; … … 739 777 } 740 778 741 $this->sql_clauses['select'] = "SELECT $fields"; 779 $found_rows = ''; 780 if ( ! $this->query_vars['no_found_rows'] ) { 781 $found_rows = 'SQL_CALC_FOUND_ROWS'; 782 } 783 784 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 742 785 $this->sql_clauses['from'] = "FROM $wpdb->comments $join"; 743 786 $this->sql_clauses['groupby'] = $groupby; -
trunk/tests/phpunit/tests/comment/query.php
r34310 r34544 1874 1874 1875 1875 } 1876 1877 /** 1878 * @ticket 8071 1879 */ 1880 public function test_no_found_rows_should_default_to_true() { 1881 $comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) ); 1882 1883 $q = new WP_Comment_Query( array( 1884 'post_id' => $this->post_id, 1885 'number' => 2, 1886 ) ); 1887 1888 $this->assertEquals( 0, $q->found_comments ); 1889 $this->assertEquals( 0, $q->max_num_pages ); 1890 } 1891 1892 /** 1893 * @ticket 8071 1894 */ 1895 public function test_should_respect_no_found_rows_true() { 1896 $comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) ); 1897 1898 $q = new WP_Comment_Query( array( 1899 'post_id' => $this->post_id, 1900 'number' => 2, 1901 'no_found_rows' => true, 1902 ) ); 1903 1904 $this->assertEquals( 0, $q->found_comments ); 1905 $this->assertEquals( 0, $q->max_num_pages ); 1906 } 1907 1908 /** 1909 * @ticket 8071 1910 */ 1911 public function test_should_respect_no_found_rows_false() { 1912 $comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) ); 1913 1914 $q = new WP_Comment_Query( array( 1915 'post_id' => $this->post_id, 1916 'number' => 2, 1917 'no_found_rows' => false, 1918 ) ); 1919 1920 $this->assertEquals( 3, $q->found_comments ); 1921 $this->assertEquals( 2, $q->max_num_pages ); 1922 } 1876 1923 }
Note: See TracChangeset
for help on using the changeset viewer.