Changes from branches/3.1/wp-includes/query.php at r17805 to trunk/wp-includes/query.php at r18268
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/query.php
r17805 r18268 850 850 851 851 /** 852 * Metadata query container 853 * 854 * @since 3.2.0 855 * @access public 856 * @var object WP_Meta_Query 857 */ 858 var $meta_query = false; 859 860 /** 852 861 * Holds the data for a single object that is queried. 853 862 * … … 1248 1257 */ 1249 1258 var $query_vars_changed = true; 1259 1260 /** 1261 * Set if post thumbnails are cached 1262 * 1263 * @since 3.2.0 1264 * @access public 1265 * @var bool 1266 */ 1267 var $thumbnails_cached = false; 1250 1268 1251 1269 /** … … 1526 1544 unset( $tax_query ); 1527 1545 1528 _parse_meta_query( $qv );1529 1530 1546 if ( empty($qv['author']) || ($qv['author'] == '0') ) { 1531 1547 $this->is_author = false; … … 1626 1642 } 1627 1643 1628 if ( !empty($qv['post_status']) ) 1629 $qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']); 1644 if ( ! empty( $qv['post_status'] ) ) { 1645 if ( is_array( $qv['post_status'] ) ) 1646 $qv['post_status'] = array_map('sanitize_key', $qv['post_status']); 1647 else 1648 $qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']); 1649 } 1630 1650 1631 1651 if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) ) … … 1897 1917 $q = $this->fill_query_vars($q); 1898 1918 1919 // Parse meta query 1920 $this->meta_query = new WP_Meta_Query(); 1921 $this->meta_query->parse_query_vars( $q ); 1922 1899 1923 // Set a flag if a pre_get_posts hook changed the query vars. 1900 1924 $hash = md5( serialize( $this->query_vars ) ); … … 2156 2180 $searchand = ' AND '; 2157 2181 } 2158 $term = esc_sql( like_escape( $q['s'] ) );2159 if ( empty($q['sentence']) && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] )2160 $search .= " OR ($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}')";2161 2182 2162 2183 if ( !empty($search) ) { … … 2230 2251 unset( $tag_query ); 2231 2252 } 2253 } 2254 2255 if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { 2256 $groupby = "{$wpdb->posts}.ID"; 2232 2257 } 2233 2258 … … 2288 2313 // Order by 2289 2314 if ( empty($q['orderby']) ) { 2290 $ q['orderby']= "$wpdb->posts.post_date " . $q['order'];2315 $orderby = "$wpdb->posts.post_date " . $q['order']; 2291 2316 } elseif ( 'none' == $q['orderby'] ) { 2292 $ q['orderby']= '';2317 $orderby = ''; 2293 2318 } else { 2294 2319 // Used to filter values … … 2301 2326 $q['orderby'] = urldecode($q['orderby']); 2302 2327 $q['orderby'] = addslashes_gpc($q['orderby']); 2303 $orderby_array = explode(' ', $q['orderby']); 2304 $q['orderby'] = ''; 2305 2306 foreach ( $orderby_array as $i => $orderby ) { 2328 2329 $orderby_array = array(); 2330 foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) { 2307 2331 // Only allow certain values for safety 2308 2332 if ( ! in_array($orderby, $allowed_keys) ) … … 2332 2356 } 2333 2357 2334 $q['orderby'] .= (($i == 0) ? '' : ',') . $orderby; 2335 } 2336 2337 // append ASC or DESC at the end 2338 if ( !empty($q['orderby'])) 2339 $q['orderby'] .= " {$q['order']}"; 2340 2341 if ( empty($q['orderby']) ) 2342 $q['orderby'] = "$wpdb->posts.post_date ".$q['order']; 2358 $orderby_array[] = $orderby; 2359 } 2360 $orderby = implode( ',', $orderby_array ); 2361 2362 if ( empty( $orderby ) ) 2363 $orderby = "$wpdb->posts.post_date ".$q['order']; 2364 else 2365 $orderby .= " {$q['order']}"; 2343 2366 } 2344 2367 … … 2386 2409 } 2387 2410 2388 if ( isset($q['post_status']) && '' != $q['post_status']) {2411 if ( ! empty( $q['post_status'] ) ) { 2389 2412 $statuswheres = array(); 2390 $q_status = explode(',', $q['post_status']); 2413 $q_status = $q['post_status']; 2414 if ( ! is_array( $q_status ) ) 2415 $q_status = explode(',', $q_status); 2391 2416 $r_status = array(); 2392 2417 $p_status = array(); 2393 2418 $e_status = array(); 2394 if ( $q['post_status'] == 'any') {2419 if ( in_array('any', $q_status) ) { 2395 2420 foreach ( get_post_stati( array('exclude_from_search' => true) ) as $status ) 2396 2421 $e_status[] = "$wpdb->posts.post_status <> '$status'"; … … 2461 2486 } 2462 2487 2463 // Parse the meta query again if query vars have changed. 2464 if ( $this->query_vars_changed ) { 2465 $meta_query_hash = md5( serialize( $q['meta_query'] ) ); 2466 $_meta_query = $q['meta_query']; 2467 unset( $q['meta_query'] ); 2468 _parse_meta_query( $q ); 2469 if ( md5( serialize( $q['meta_query'] ) ) != $meta_query_hash && is_array( $_meta_query ) ) 2470 $q['meta_query'] = array_merge( $_meta_query, $q['meta_query'] ); 2471 } 2472 2473 if ( !empty( $q['meta_query'] ) ) { 2474 $clauses = call_user_func_array( '_get_meta_sql', array( $q['meta_query'], 'post', $wpdb->posts, 'ID', &$this) ); 2488 if ( !empty( $this->meta_query->queries ) ) { 2489 $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 2475 2490 $join .= $clauses['join']; 2476 2491 $where .= $clauses['where']; 2477 }2478 2479 if ( ! empty( $this->tax_query->queries ) || ! empty( $q['meta_query'] ) ) {2480 $groupby = "{$wpdb->posts}.ID";2481 2492 } 2482 2493 … … 2542 2553 $where = "AND 0"; 2543 2554 } 2544 2545 $orderby = $q['orderby'];2546 2555 2547 2556 $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); … … 2968 2977 2969 2978 /** 2970 * PHP4 type constructor.2979 * Constructor. 2971 2980 * 2972 2981 * Sets up the WordPress query, if parameter is not empty. … … 2978 2987 * @return WP_Query 2979 2988 */ 2980 function WP_Query($query = '') {2989 function __construct($query = '') { 2981 2990 if ( ! empty($query) ) { 2982 2991 $this->query($query); … … 3510 3519 return; 3511 3520 3512 wp_redirect( $link, '301'); // Permanent redirect3521 wp_redirect( $link, 301 ); // Permanent redirect 3513 3522 exit; 3514 3523 endif;
Note: See TracChangeset
for help on using the changeset viewer.