Skip to content

Commit b4c617d

Browse files
westonruterjeherve
authored andcommitted
Switch to filtering the limit earlier
See #10552 (comment)
1 parent aad4330 commit b4c617d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/wp-includes/general-template.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,9 +2031,19 @@ function wp_get_archives( $args = '' ) {
20312031
$parsed_args['type'] = 'monthly';
20322032
}
20332033

2034-
if ( ! empty( $parsed_args['limit'] ) ) {
2035-
$parsed_args['limit'] = absint( $parsed_args['limit'] );
2036-
$parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit'];
2034+
/**
2035+
* Filters the limit for the number of posts to include in the archive.
2036+
*
2037+
* @since 7.0.0
2038+
*
2039+
* @param int $limit The limit for the number of posts to include in the archive. Default 0.
2040+
* @param array $parsed_args An array of default arguments.
2041+
*/
2042+
$limit_number = (int) apply_filters( 'getarchives_limit', absint( $parsed_args['limit'] ), $parsed_args );
2043+
if ( $limit_number > 0 ) {
2044+
$limit = " LIMIT $limit_number";
2045+
} else {
2046+
$limit = '';
20372047
}
20382048

20392049
$order = strtoupper( $parsed_args['order'] );
@@ -2070,16 +2080,6 @@ function wp_get_archives( $args = '' ) {
20702080

20712081
$last_changed = wp_cache_get_last_changed( 'posts' );
20722082

2073-
/**
2074-
* Filters the SQL LIMIT clause for retrieving archives.
2075-
*
2076-
* @since 7.0.0
2077-
*
2078-
* @param string $limit The limit of the query for the `wp_get_archives` function.
2079-
* @param array $parsed_args An array of default arguments.
2080-
*/
2081-
$limit = apply_filters( 'getarchives_limit', $parsed_args['limit'], $parsed_args );
2082-
20832083
if ( 'monthly' === $parsed_args['type'] ) {
20842084
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
20852085
$key = md5( $query );

0 commit comments

Comments
 (0)