Skip to content

Commit 9b80d11

Browse files
authored
Merge pull request #3063 from mohjak/master
fix: taking care about the case of empty order by
2 parents d5ccf03 + ed60fa1 commit 9b80d11

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Data/Config.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)