Introduce `paged` argument to `WP_Comment_Query`.

Using `paged` with `number` allows developers to request
paginated comment results without having to do a manual offset
calculation.

Props AdamWills.
Fixes #38268.
Built from https://develop.svn.wordpress.org/trunk@41287


git-svn-id: http://core.svn.wordpress.org/trunk@41127 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2017-08-21 15:35:46 +00:00
parent 1770cc7b87
commit c080c0a2ea
2 changed files with 7 additions and 2 deletions

View File

@ -140,6 +140,7 @@ class WP_Comment_Query {
* `$hierarchical`, and `$update_comment_post_cache` were added. * `$hierarchical`, and `$update_comment_post_cache` were added.
* @since 4.5.0 Introduced the `$author_url` argument. * @since 4.5.0 Introduced the `$author_url` argument.
* @since 4.6.0 Introduced the `$cache_domain` argument. * @since 4.6.0 Introduced the `$cache_domain` argument.
* @since 4.9.0 Introduced the `$paged` argument.
* *
* @param string|array $query { * @param string|array $query {
* Optional. Array or query string of comment query parameters. Default empty. * Optional. Array or query string of comment query parameters. Default empty.
@ -170,6 +171,8 @@ class WP_Comment_Query {
* See WP_Meta_Query. Default empty. * See WP_Meta_Query. Default empty.
* @type int $number Maximum number of comments to retrieve. * @type int $number Maximum number of comments to retrieve.
* Default empty (no limit). * Default empty (no limit).
* @type int $paged When used with $number, defines the page of results to return.
* When used with $offset, $offset takes precedence. Default 1.
* @type int $offset Number of comments to offset the query. Used to build * @type int $offset Number of comments to offset the query. Used to build
* LIMIT clause. Default 0. * LIMIT clause. Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query.
@ -263,6 +266,7 @@ class WP_Comment_Query {
'no_found_rows' => true, 'no_found_rows' => true,
'orderby' => '', 'orderby' => '',
'order' => 'DESC', 'order' => 'DESC',
'paged' => 1,
'parent' => '', 'parent' => '',
'parent__in' => '', 'parent__in' => '',
'parent__not_in' => '', 'parent__not_in' => '',
@ -628,12 +632,13 @@ class WP_Comment_Query {
$number = absint( $this->query_vars['number'] ); $number = absint( $this->query_vars['number'] );
$offset = absint( $this->query_vars['offset'] ); $offset = absint( $this->query_vars['offset'] );
$paged = absint( $this->query_vars['paged'] );
if ( ! empty( $number ) ) { if ( ! empty( $number ) ) {
if ( $offset ) { if ( $offset ) {
$limits = 'LIMIT ' . $offset . ',' . $number; $limits = 'LIMIT ' . $offset . ',' . $number;
} else { } else {
$limits = 'LIMIT ' . $number; $limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
} }
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-alpha-41286'; $wp_version = '4.9-alpha-41287';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.