Skip to content

Commit 4e17686

Browse files
committed
Enhance WP_Query ordering logic by normalizing 'date' to 'date, ID' for consistent cache key generation. This change ensures deterministic results when 'date' is specified as the orderby value, improving query consistency.
1 parent eac001e commit 4e17686

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/wp-includes/class-wp-query.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,9 +5109,13 @@ protected function generate_cache_key( array $args, $sql ) {
51095109
sort( $args['post_status'] );
51105110
}
51115111

5112+
// Add a default orderby value of date to ensure same cache key generation.
51125113
// Add a default orderby value of date to ensure same cache key generation.
51135114
if ( ! isset( $args['orderby'] ) ) {
51145115
$args['orderby'] = 'date, ID';
5116+
} elseif ( $args['orderby'] === 'date' ) {
5117+
// Normalize 'date' to 'date, ID' to match deterministic ordering
5118+
$args['orderby'] = 'date, ID';
51155119
}
51165120

51175121
$placeholder = $wpdb->placeholder_escape();

0 commit comments

Comments
 (0)