diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
index ef8b6d5..67dfcae 100644
|
|
class WP_Comment_Query { |
183 | 183 | * See WP_Meta_Query. Default empty. |
184 | 184 | * @type int $number Maximum number of comments to retrieve. |
185 | 185 | * Default empty (no limit). |
| 186 | * @type int $paged When used with number, defines the page of results to return. |
| 187 | * Default 1. |
186 | 188 | * @type int $offset Number of comments to offset the query. Used to build |
187 | 189 | * LIMIT clause. Default 0. |
188 | 190 | * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. |
… |
… |
class WP_Comment_Query { |
276 | 278 | 'no_found_rows' => true, |
277 | 279 | 'orderby' => '', |
278 | 280 | 'order' => 'DESC', |
| 281 | 'paged' => '1', |
279 | 282 | 'parent' => '', |
280 | 283 | 'parent__in' => '', |
281 | 284 | 'parent__not_in' => '', |
… |
… |
class WP_Comment_Query { |
640 | 643 | |
641 | 644 | $number = absint( $this->query_vars['number'] ); |
642 | 645 | $offset = absint( $this->query_vars['offset'] ); |
| 646 | $paged = absint( $this->query_vars['paged'] ); |
643 | 647 | |
644 | 648 | if ( ! empty( $number ) ) { |
645 | 649 | if ( $offset ) { |
646 | 650 | $limits = 'LIMIT ' . $offset . ',' . $number; |
647 | 651 | } else { |
648 | | $limits = 'LIMIT ' . $number; |
| 652 | $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number; |
649 | 653 | } |
650 | 654 | } |
651 | 655 | |
diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
index ff4e3ac..beb8c43 100644
|
|
class Tests_Comment_Query extends WP_UnitTestCase { |
1561 | 1561 | $this->assertEquals( 2, $found ); |
1562 | 1562 | } |
1563 | 1563 | |
| 1564 | /** |
| 1565 | * @ticket 38268 |
| 1566 | */ |
| 1567 | public function test_pagination_query() { |
| 1568 | $comments = self::factory()->comment->create_many( 4, array( |
| 1569 | 'comment_post_ID' => self::$post_id, |
| 1570 | ) ); |
| 1571 | |
| 1572 | $query1 = new WP_Comment_Query(); |
| 1573 | $found1 = $query1->query( array( |
| 1574 | 'paged' => 2, |
| 1575 | 'number' => 2 |
| 1576 | ) ); |
| 1577 | |
| 1578 | $query2 = new WP_Comment_Query(); |
| 1579 | $found2 = $query2->query( |
| 1580 | array( |
| 1581 | 'offset' => 2, |
| 1582 | 'number' => 2 |
| 1583 | ) |
| 1584 | ); |
| 1585 | $this->assertEqualSets( $found1, $found2 ); |
| 1586 | } |
| 1587 | |
| 1588 | /** |
| 1589 | * @ticket 38268 |
| 1590 | */ |
| 1591 | public function test_pagination_offset_conflict() { |
| 1592 | $comments = self::factory()->comment->create_many( 4, array( |
| 1593 | 'comment_post_ID' => self::$post_id, |
| 1594 | ) ); |
| 1595 | $query1 = new WP_Comment_Query(); |
| 1596 | $found1 = $query1->query( array( |
| 1597 | 'paged' => 2, |
| 1598 | 'offset' => 1, |
| 1599 | 'number' => 2 |
| 1600 | ) ); |
| 1601 | |
| 1602 | $query2 = new WP_Comment_Query(); |
| 1603 | $found2 = $query2->query( |
| 1604 | array( |
| 1605 | 'offset' => 1, |
| 1606 | 'number' => 2 |
| 1607 | ) |
| 1608 | ); |
| 1609 | $this->assertEqualSets( $found1, $found2 ); |
| 1610 | } |
| 1611 | |
1564 | 1612 | public function test_post_type_single_value() { |
1565 | 1613 | register_post_type( 'post-type-1' ); |
1566 | 1614 | register_post_type( 'post-type-2' ); |