Changeset 41287
- Timestamp:
- 08/21/2017 03:34:19 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r41215 r41287 141 141 * @since 4.5.0 Introduced the `$author_url` argument. 142 142 * @since 4.6.0 Introduced the `$cache_domain` argument. 143 * @since 4.9.0 Introduced the `$paged` argument. 143 144 * 144 145 * @param string|array $query { … … 171 172 * @type int $number Maximum number of comments to retrieve. 172 173 * Default empty (no limit). 174 * @type int $paged When used with $number, defines the page of results to return. 175 * When used with $offset, $offset takes precedence. Default 1. 173 176 * @type int $offset Number of comments to offset the query. Used to build 174 177 * LIMIT clause. Default 0. … … 264 267 'orderby' => '', 265 268 'order' => 'DESC', 269 'paged' => 1, 266 270 'parent' => '', 267 271 'parent__in' => '', … … 629 633 $number = absint( $this->query_vars['number'] ); 630 634 $offset = absint( $this->query_vars['offset'] ); 635 $paged = absint( $this->query_vars['paged'] ); 631 636 632 637 if ( ! empty( $number ) ) { … … 634 639 $limits = 'LIMIT ' . $offset . ',' . $number; 635 640 } else { 636 $limits = 'LIMIT ' . $number;641 $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number; 637 642 } 638 643 } -
trunk/tests/phpunit/tests/comment/query.php
r41190 r41287 1562 1562 } 1563 1563 1564 /** 1565 * @ticket 38268 1566 */ 1567 public function test_paged() { 1568 $now = time(); 1569 1570 $c1 = self::factory()->comment->create( array( 1571 'comment_post_ID' => self::$post_id, 1572 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 50 ), 1573 ) ); 1574 $c2 = self::factory()->comment->create( array( 1575 'comment_post_ID' => self::$post_id, 1576 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ), 1577 ) ); 1578 $c3 = self::factory()->comment->create( array( 1579 'comment_post_ID' => self::$post_id, 1580 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ), 1581 ) ); 1582 $c4 = self::factory()->comment->create( array( 1583 'comment_post_ID' => self::$post_id, 1584 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ), 1585 ) ); 1586 1587 $query = new WP_Comment_Query(); 1588 $found = $query->query( array( 1589 'paged' => 2, 1590 'number' => 2, 1591 'orderby' => 'comment_date_gmt', 1592 'order' => 'DESC', 1593 'fields' => 'ids', 1594 ) ); 1595 1596 $expected = array( $c2, $c1 ); 1597 $this->assertSame( $expected, $found ); 1598 } 1599 1600 /** 1601 * @ticket 38268 1602 */ 1603 public function test_offset_should_take_precedence_over_paged() { 1604 $now = time(); 1605 1606 $c1 = self::factory()->comment->create( array( 1607 'comment_post_ID' => self::$post_id, 1608 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 50 ), 1609 ) ); 1610 $c2 = self::factory()->comment->create( array( 1611 'comment_post_ID' => self::$post_id, 1612 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ), 1613 ) ); 1614 $c3 = self::factory()->comment->create( array( 1615 'comment_post_ID' => self::$post_id, 1616 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ), 1617 ) ); 1618 $c4 = self::factory()->comment->create( array( 1619 'comment_post_ID' => self::$post_id, 1620 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ), 1621 ) ); 1622 1623 $query = new WP_Comment_Query(); 1624 $found = $query->query( array( 1625 'paged' => 2, 1626 'offset' => 1, 1627 'number' => 2, 1628 'orderby' => 'comment_date_gmt', 1629 'order' => 'DESC', 1630 'fields' => 'ids', 1631 ) ); 1632 1633 $expected = array( $c3, $c2 ); 1634 1635 $this->assertSame( $expected, $found ); 1636 } 1637 1564 1638 public function test_post_type_single_value() { 1565 1639 register_post_type( 'post-type-1' );
Note: See TracChangeset
for help on using the changeset viewer.