Make WordPress Core

Ticket #47642: patch.47642.20220204.1

File patch.47642.20220204.1, 1.5 KB (added by ramon fincken, 5 years ago)

patch.47642.20220204.1

Line 
1Index: src/wp-includes/class-wp-query.php
2===================================================================
3--- src/wp-includes/class-wp-query.php (revision 52673)
4+++ src/wp-includes/class-wp-query.php (working copy)
5@@ -2367,7 +2367,24 @@
6 } else {
7 $q['orderby'] = urldecode( $q['orderby'] );
8 $q['orderby'] = addslashes_gpc( $q['orderby'] );
9-
10+
11+ // https://core.trac.wordpress.org/ticket/47642
12+ // Database engine fix to prevent strange (duplicate or missing) results in paginated resultsets
13+ // Adds the unique ID primary key if needed
14+ $do_not_force_ID = array( 'ID', 'rand', 'relevance' );
15+ if ( is_array( $q['orderby'] ) ) {
16+ if( count( array_intersect_key( $q['orderby'], $do_not_force_ID ) ) == 0 ) {
17+ // No match found so we need to add our unique ID here
18+ $q['orderby']['ID'] = 'ASC';
19+ }
20+ } else {
21+ // Not an array, test as string
22+ if( !in_array( $q['orderby'], $do_not_force_ID ) ) {
23+ // No match found so we need to add our unique ID here, note the space
24+ $q['orderby'] .= ' ID';
25+ }
26+ }
27+
28 foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) {
29 $parsed = $this->parse_orderby( $orderby );
30 // Only allow certain values for safety.