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:
parent
1770cc7b87
commit
c080c0a2ea
|
@ -140,6 +140,7 @@ class WP_Comment_Query {
|
|||
* `$hierarchical`, and `$update_comment_post_cache` were added.
|
||||
* @since 4.5.0 Introduced the `$author_url` argument.
|
||||
* @since 4.6.0 Introduced the `$cache_domain` argument.
|
||||
* @since 4.9.0 Introduced the `$paged` argument.
|
||||
*
|
||||
* @param string|array $query {
|
||||
* 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.
|
||||
* @type int $number Maximum number of comments to retrieve.
|
||||
* 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
|
||||
* LIMIT clause. Default 0.
|
||||
* @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,
|
||||
'orderby' => '',
|
||||
'order' => 'DESC',
|
||||
'paged' => 1,
|
||||
'parent' => '',
|
||||
'parent__in' => '',
|
||||
'parent__not_in' => '',
|
||||
|
@ -628,12 +632,13 @@ class WP_Comment_Query {
|
|||
|
||||
$number = absint( $this->query_vars['number'] );
|
||||
$offset = absint( $this->query_vars['offset'] );
|
||||
$paged = absint( $this->query_vars['paged'] );
|
||||
|
||||
if ( ! empty( $number ) ) {
|
||||
if ( $offset ) {
|
||||
$limits = 'LIMIT ' . $offset . ',' . $number;
|
||||
} else {
|
||||
$limits = 'LIMIT ' . $number;
|
||||
$limits = 'LIMIT ' . ( $number * ( $paged - 1 ) ) . ',' . $number;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @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.
|
||||
|
|
Loading…
Reference in New Issue