WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/06/2010 11:28:59 AM (10 years ago)
Author:
scribu
Message:

Use _wp_meta_sql() in WP_Query. See #14572. See #14645

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r15547 r15581  
    22122212
    22132213        // postmeta queries
    2214         if ( ! empty($q['meta_key']) || ! empty($q['meta_value']) )
    2215             $join .= " JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) ";
    2216         if ( ! empty($q['meta_key']) )
    2217             $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s ", $q['meta_key']);
    2218         if ( ! empty($q['meta_value']) ) {
    2219             if ( empty($q['meta_compare']) || ! in_array($q['meta_compare'], array('=', '!=', '>', '>=', '<', '<=')) )
    2220                 $q['meta_compare'] = '=';
    2221 
    2222             $where .= $wpdb->prepare("AND $wpdb->postmeta.meta_value {$q['meta_compare']} %s ", $q['meta_value']);
    2223         }
     2214        $meta_query = wp_array_slice_assoc( $q, array( 'meta_key', 'meta_value', 'meta_compare' ) );
     2215        list( $meta_join, $meta_where ) = _wp_meta_sql( array( $meta_query ), $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' );
     2216        $join .= $meta_join;
     2217        $where .= $meta_where;
    22242218
    22252219        // Apply filters on where and join prior to paging so that any
Note: See TracChangeset for help on using the changeset viewer.