-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Get archives: add filter to customize query LIMIT clause #10552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 3 commits
83d27d8
0259158
4cac4dc
aad4330
b4c617d
1ac21ca
7ce9d9f
750ca84
f4ec0f7
2160d0c
6cfa1b9
9ee87b6
ce14af6
ecdeb3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2070,7 +2070,15 @@ function wp_get_archives( $args = '' ) { | |||||||||
|
|
||||||||||
| $last_changed = wp_cache_get_last_changed( 'posts' ); | ||||||||||
|
|
||||||||||
| $limit = $parsed_args['limit']; | ||||||||||
| /** | ||||||||||
| * Filters the SQL LIMIT clause for retrieving archives. | ||||||||||
| * | ||||||||||
| * @since 7.0.0 | ||||||||||
| * | ||||||||||
| * @param string $limit The limit of the query for the `wp_get_archives` function. | ||||||||||
| * @param array $parsed_args An array of default arguments. | ||||||||||
| */ | ||||||||||
| $limit = apply_filters( 'getarchives_limit', $parsed_args['limit'], $parsed_args ); | ||||||||||
|
||||||||||
| if ( ! empty( $parsed_args['limit'] ) ) { | |
| $parsed_args['limit'] = absint( $parsed_args['limit'] ); | |
| $parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit']; | |
| } |
It could be:
/**
* Filters the limit for the number of posts to include in the archive.
*
* @since 7.0.0
*
* @param int $limit The limit for the number of posts to include in the archive. Default 0.
* @param array $parsed_args An array of default arguments.
*/
$limit_number = (int) apply_filters( 'getarchives_limit', absint( $parsed_args['limit'] ), $parsed_args );
if ( $limit_number > 0 ) {
$limit = " LIMIT $limit_number";
} else {
$limit = '';
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I updated the code sample to set the $limit variable.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can certainly do that. I pushed b4c617d with your exact suggestion.
I wondered if we needed to both cast as an integer and use absint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I personally wouldn't have used absint() to begin with.
Uh oh!
There was an error while loading. Please reload this page.