@@ -2558,14 +2558,6 @@ public function get_posts() {
25582558 $ has_id_orderby = true ;
25592559 }
25602560 }
2561-
2562- // Add ID as tie-breaker if needed and not already present
2563- if ( $ needs_deterministic_orderby && ! $ has_id_orderby ) {
2564- $ orderby_array [] = "{$ wpdb ->posts }.ID " . $ query_vars ['order ' ];
2565- }
2566-
2567- $ orderby = implode ( ', ' , $ orderby_array );
2568-
25692561 } else {
25702562 $ query_vars ['orderby ' ] = urldecode ( $ query_vars ['orderby ' ] );
25712563 $ query_vars ['orderby ' ] = addslashes_gpc ( $ query_vars ['orderby ' ] );
@@ -2586,16 +2578,18 @@ public function get_posts() {
25862578 $ has_id_orderby = true ;
25872579 }
25882580 }
2589- $ orderby = implode ( ' , ' , $ orderby_array );
2581+ }
25902582
2591- if ( empty ( $ orderby ) ) {
2592- $ orderby = "{$ wpdb ->posts }.post_date " . $ query_vars ['order ' ] . ', ' . "{$ wpdb ->posts }.ID " . $ query_vars ['order ' ];
2593- } elseif ( $ needs_deterministic_orderby && ! $ has_id_orderby ) {
2594- // Add ID as tie-breaker for deterministic ordering
2595- $ orderby .= ", {$ wpdb ->posts }.ID " . $ query_vars ['order ' ];
2596- } elseif ( ! empty ( $ query_vars ['order ' ] ) ) {
2597- $ orderby .= " {$ query_vars ['order ' ]}" ;
2598- }
2583+ // Add ID as tie-breaker if needed and not already present
2584+ if ( $ needs_deterministic_orderby && ! $ has_id_orderby ) {
2585+ $ orderby_array [] = "{$ wpdb ->posts }.ID " . $ query_vars ['order ' ];
2586+ }
2587+
2588+ // Build the final orderby string
2589+ if ( empty ( $ orderby_array ) ) {
2590+ $ orderby = "{$ wpdb ->posts }.post_date " . $ query_vars ['order ' ] . ', ' . "{$ wpdb ->posts }.ID " . $ query_vars ['order ' ];
2591+ } else {
2592+ $ orderby = implode ( ', ' , $ orderby_array );
25992593 }
26002594 }
26012595
0 commit comments