Changeset 28659
- Timestamp:
- 06/04/2014 05:47:19 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/meta.php
r28522 r28659 973 973 } 974 974 975 $where_meta_key = array(); 975 976 foreach ( $queries as $k => $q ) { 976 977 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; … … 1015 1016 1016 1017 $where[$k] = ''; 1017 if ( !empty( $meta_key ) ) 1018 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); 1018 if ( ! empty( $meta_key ) ) { 1019 if ( isset( $q['compare'] ) ) { 1020 $where_meta_key[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); 1021 } else { 1022 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); 1023 } 1024 } 1019 1025 1020 1026 if ( is_null( $meta_value ) ) { 1021 if ( empty( $where[$k] ) )1027 if ( empty( $where[$k] ) && empty( $where_meta_key ) ) { 1022 1028 unset( $join[$i] ); 1029 } 1023 1030 continue; 1024 1031 } … … 1060 1067 else 1061 1068 $where = ' AND (' . implode( "\n{$this->relation} ", $where ) . ' )'; 1069 1070 if ( ! empty( $where_meta_key ) ) { 1071 $where .= "\nAND " . implode( "\nAND ", $where_meta_key ); 1072 } 1062 1073 1063 1074 $join = implode( "\n", $join ); -
trunk/tests/phpunit/tests/meta.php
r27562 r28659 198 198 } 199 199 } 200 201 function test_query_meta_query_order() { 202 $post1 = $this->factory->post->create( array( 'post_title' => 'meta-value-1', 'post_date' => '2007-01-01 00:00:00' ) ); 203 $post2 = $this->factory->post->create( array( 'post_title' => 'meta-value-2', 'post_date' => '2007-01-01 00:00:00' ) ); 204 $post3 = $this->factory->post->create( array( 'post_title' => 'meta-value-3', 'post_date' => '2007-01-01 00:00:00' ) ); 205 206 add_post_meta( $post1, 'order', 1 ); 207 add_post_meta( $post2, 'order', 2 ); 208 add_post_meta( $post3, 'order', 3 ); 209 210 $args = array( 211 'post_type' => 'post', 212 'meta_key' => 'order', 213 'meta_value' => 1, 214 'meta_compare' => '>=', 215 'orderby' => 'meta_value' 216 ); 217 218 $args2 = array( 219 'post_type' => 'post', 220 'meta_key' => 'order', 221 'meta_value' => 1, 222 'meta_compare' => '>=', 223 'orderby' => 'meta_value', 224 'meta_query' => array( 225 'relation' => 'OR', 226 array( 227 'key' => 'order', 228 'compare' => '>=', 229 'value' => 1 230 ) 231 ) 232 ); 233 234 $posts = get_posts( $args ); 235 $posts2 = get_posts( $args2 ); 236 237 $this->assertEquals( wp_list_pluck( $posts, 'post_title' ), wp_list_pluck( $posts2, 'post_title' ) ); 238 } 200 239 }
Note: See TracChangeset
for help on using the changeset viewer.