@@ -205,7 +205,7 @@ public function graphql_wp_query_cursor_pagination_stability( string $orderby, W
205205 $ key = $ cursor ->get_cursor_id_key ();
206206
207207 // If there is a cursor compare in the arguments, use it as the stablizer for cursors.
208- return "{$ orderby }, {$ key } {$ order }" ;
208+ return ( $ orderby ? "{$ orderby }, " : '' ) . " {$ key } {$ order }" ;
209209 }
210210
211211 /**
@@ -307,7 +307,7 @@ public function graphql_wp_user_query_cursor_pagination_stability( $orderby, \WP
307307 $ cursor = new UserCursor ( $ query ->query_vars );
308308 $ key = $ cursor ->get_cursor_id_key ();
309309
310- return "{$ orderby }, {$ key } {$ order }" ;
310+ return ( $ orderby ? "{$ orderby }, " : '' ) . " {$ key } {$ order }" ;
311311 }
312312
313313 /**
@@ -420,16 +420,21 @@ public function graphql_wp_term_query_cursor_pagination_support( array $pieces,
420420 $ pieces ['where ' ] = $ pieces ['where ' ] . $ before_cursor ->get_where ();
421421 }
422422
423- // Check the cursor compare order
423+ // Check the cursor compare order.
424424 $ order = '> ' === $ args ['graphql_cursor_compare ' ] ? 'ASC ' : 'DESC ' ;
425425
426426 // Get Cursor ID key.
427427 $ cursor = new TermObjectCursor ( $ args );
428428 $ key = $ cursor ->get_cursor_id_key ();
429429
430430 // If there is a cursor compare in the arguments, use it as the stabilizer for cursors.
431- $ pieces ['orderby ' ] = "{$ pieces ['orderby ' ]} {$ pieces ['order ' ]}, {$ key } {$ order }" ;
432- $ pieces ['order ' ] = '' ;
431+ if ( ! empty ( $ pieces ['orderby ' ] ) ) {
432+ $ pieces ['orderby ' ] = "{$ pieces ['orderby ' ]} {$ pieces ['order ' ]}, {$ key } {$ order }" ;
433+ } else {
434+ $ pieces ['orderby ' ] = "ORDER BY {$ key } {$ order }" ;
435+ }
436+
437+ $ pieces ['order ' ] = '' ;
433438
434439 return $ pieces ;
435440 }
0 commit comments