Changeset 58122 for trunk/src/wp-includes/class-wp-query.php
- Timestamp:
- 05/08/2024 10:49:46 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r57761 r58122 2265 2265 } elseif ( count( $post_type ) === 1 ) { 2266 2266 $post_type = $post_type[0]; 2267 } else { 2268 // Sort post types to ensure same cache key generation. 2269 sort( $post_type ); 2267 2270 } 2268 2271 … … 2543 2546 } 2544 2547 } elseif ( ! empty( $post_type ) && is_array( $post_type ) ) { 2548 // Sort post types to ensure same cache key generation. 2549 sort( $post_type ); 2545 2550 $post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')"; 2546 2551 } elseif ( ! empty( $post_type ) ) { … … 2648 2653 2649 2654 if ( ! empty( $queried_post_types ) ) { 2650 2655 sort( $queried_post_types ); 2651 2656 $status_type_clauses = array(); 2652 2657 … … 3105 3110 } 3106 3111 3107 // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841. 3112 /* 3113 * Beginning of the string is on a new line to prevent leading whitespace. 3114 * 3115 * The additional indentation of subsequent lines is to ensure the SQL 3116 * queries are identical to those generated when splitting queries. This 3117 * improves caching of the query by ensuring the same cache key is 3118 * generated for the same database queries functionally. 3119 * 3120 * See https://core.trac.wordpress.org/ticket/56841. 3121 * See https://github.com/WordPress/wordpress-develop/pull/6393#issuecomment-2088217429 3122 */ 3108 3123 $old_request = 3109 3124 "SELECT $found_rows $distinct $fields 3110 FROM {$wpdb->posts} $join3111 WHERE 1=1 $where3112 $groupby3113 $orderby3114 $limits";3125 FROM {$wpdb->posts} $join 3126 WHERE 1=1 $where 3127 $groupby 3128 $orderby 3129 $limits"; 3115 3130 3116 3131 $this->request = $old_request; … … 4857 4872 ); 4858 4873 4874 if ( empty( $args['post_type'] ) ) { 4875 if ( $this->is_attachment ) { 4876 $args['post_type'] = 'attachment'; 4877 } elseif ( $this->is_page ) { 4878 $args['post_type'] = 'page'; 4879 } else { 4880 $args['post_type'] = 'post'; 4881 } 4882 } elseif ( 'any' === $args['post_type'] ) { 4883 $args['post_type'] = array_values( get_post_types( array( 'exclude_from_search' => false ) ) ); 4884 } 4885 $args['post_type'] = (array) $args['post_type']; 4886 // Sort post types to ensure same cache key generation. 4887 sort( $args['post_type'] ); 4888 4889 if ( isset( $args['post_status'] ) ) { 4890 $args['post_status'] = (array) $args['post_status']; 4891 // Sort post status to ensure same cache key generation. 4892 sort( $args['post_status'] ); 4893 } 4894 4895 // Add a default orderby value of date to ensure same cache key generation. 4896 if ( ! isset( $q['orderby'] ) ) { 4897 $args['orderby'] = 'date'; 4898 } 4899 4859 4900 $placeholder = $wpdb->placeholder_escape(); 4860 4901 array_walk_recursive( … … 4875 4916 ); 4876 4917 4918 ksort( $args ); 4919 4877 4920 // Replace wpdb placeholder in the SQL statement used by the cache key. 4878 4921 $sql = $wpdb->remove_placeholder_escape( $sql );
Note: See TracChangeset
for help on using the changeset viewer.