mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@41287 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user