File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -3324,8 +3324,8 @@ public function get_posts() {
33243324 }
33253325
33263326 $ cache_key = $ this ->generate_cache_key ( $ query_vars , $ new_request );
3327-
33283327 $ cache_found = false ;
3328+
33293329 if ( null === $ this ->posts ) {
33303330 $ cached_results = wp_cache_get_salted ( $ cache_key , 'post-queries ' , $ last_changed );
33313331
@@ -5109,12 +5109,14 @@ 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.
5113- // Add a default orderby value of date to ensure same cache key generation.
5112+
5113+ /*
5114+ * Ensure deterministic ordering to prevent duplicate records across pages.
5115+ * When multiple posts have the same value for a field, add ID as secondary sort to guarantee consistent ordering.
5116+ */
51145117 if ( ! isset ( $ args ['orderby ' ] ) ) {
51155118 $ args ['orderby ' ] = 'date, ID ' ;
5116- } elseif ( $ args ['orderby ' ] === 'date ' ) {
5117- // Normalize 'date' to 'date, ID' to match deterministic ordering
5119+ } elseif ( 'date ' === $ args ['orderby ' ] ) {
51185120 $ args ['orderby ' ] = 'date, ID ' ;
51195121 }
51205122
You can’t perform that action at this time.
0 commit comments