Changeset 15580 for trunk/wp-includes/functions.php
- Timestamp:
- 09/06/2010 11:04:50 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r15579 r15580 4244 4244 * 4245 4245 * @param array $queries An array of queries 4246 * @param string $meta_id_column The column that holds the object id 4247 * @return string 4248 */ 4249 function _wp_meta_sql( $queries, $meta_id_column ) { 4246 * @param string $primary_table 4247 * @param string $primary_id_column 4248 * @param string $meta_table 4249 * @param string $meta_id_column 4250 * @return array( $join_sql, $where_sql ) 4251 */ 4252 function _wp_meta_sql( $queries, $primary_table, $primary_id_column, $meta_table, $meta_id_column ) { 4250 4253 global $wpdb; 4251 4254 … … 4263 4266 continue; 4264 4267 4265 $clause = $wpdb->prepare( "WHEN %s THEN meta_value ", $meta_key );4266 4267 4268 if ( empty( $meta_value ) ) { 4268 $clauses[ ] = $clause . "IS NOT NULL";4269 $clauses[ $meta_key ] = ""; 4269 4270 } elseif ( 'like' == $meta_compare ) { 4270 $clauses[ ] = $clause .$wpdb->prepare( "LIKE %s", '%' . like_escape( $meta_value ) . '%' );4271 $clauses[ $meta_key ] = $wpdb->prepare( "LIKE %s", '%' . like_escape( $meta_value ) . '%' ); 4271 4272 } else { 4272 $clauses[ ] = $clause .$wpdb->prepare( "$meta_compare %s", $meta_value );4273 $clauses[ $meta_key ] = $wpdb->prepare( "$meta_compare %s", $meta_value ); 4273 4274 } 4274 4275 } 4275 4276 4276 4277 if ( empty( $clauses ) ) 4277 return ''; 4278 4279 return " 4280 AND CASE meta_key 4281 " . implode( "\n", $clauses ) . " 4282 END 4283 GROUP BY $meta_id_column 4284 HAVING COUNT(*) = " . count( $clauses ); 4285 } 4286 4278 return array('', ''); 4279 4280 $join = ''; 4281 $where = ''; 4282 4283 $i = 0; 4284 foreach ( $clauses as $meta_key => $value_query ) { 4285 $alias = $i ? 'mt' . $i : $meta_table; 4286 4287 $join .= "\nINNER JOIN $meta_table"; 4288 $join .= $i ? " AS $alias" : ''; 4289 $join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; 4290 4291 $where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key ); 4292 if ( !empty( $value_query ) ) 4293 $where .= " AND $alias.meta_value $value_query"; 4294 4295 $i++; 4296 } 4297 4298 return array( $join, $where ); 4299 } 4287 4300 4288 4301 /*
Note: See TracChangeset
for help on using the changeset viewer.