WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/04/2010 06:57:13 PM (10 years ago)
Author:
scribu
Message:

Introduce WP_Object_Query. See #15032

File:
1 edited

Legend:

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

    r15714 r15715  
    42584258
    42594259/*
    4260  * Used internally to generate an SQL string for searching across multiple meta key = value pairs
    4261  *
    4262  * @access private
    4263  * @since 3.1.0
    4264  *
    4265  * @param array $queries An array of queries
    4266  * @param string $primary_table
    4267  * @param string $primary_id_column
    4268  * @param string $meta_table
    4269  * @param string $meta_id_column
    4270  * @return array( $join_sql, $where_sql )
    4271  */
    4272 function _wp_meta_sql( $queries, $primary_table, $primary_id_column, $meta_table, $meta_id_column ) {
    4273     global $wpdb;
    4274 
    4275     $clauses = array();
    4276 
    4277     $join = '';
    4278     $where = '';
    4279     $i = 0;
    4280     foreach ( $queries as $q ) {
    4281         $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    4282         $meta_value = isset( $q['value'] ) ? trim( $q['value'] ) : '';
    4283         $meta_compare = isset( $q['compare'] ) ? $q['compare'] : '=';
    4284 
    4285         if ( !in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'like' ) ) )
    4286             $meta_compare = '=';
    4287 
    4288         if ( empty( $meta_key ) && empty( $meta_value ) )
    4289             continue;
    4290 
    4291         $alias = $i ? 'mt' . $i : $meta_table;
    4292 
    4293         $join .= "\nINNER JOIN $meta_table";
    4294         $join .= $i ? " AS $alias" : '';
    4295         $join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
    4296 
    4297         $i++;
    4298 
    4299         if ( !empty( $meta_key ) )
    4300             $where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
    4301 
    4302         if ( empty( $meta_value ) )
    4303             continue;
    4304 
    4305         if ( 'like' == $meta_compare ) {
    4306             $where .= $wpdb->prepare( " AND $alias.meta_value LIKE %s", '%' . like_escape( $meta_value ) . '%' );
    4307         } else {
    4308             $where .= $wpdb->prepare( " AND $alias.meta_value $meta_compare %s", $meta_value );
    4309         }
    4310     }
    4311 
    4312     return array( $join, $where );
    4313 }
    4314 
    4315 /*
    43164260 * Used internally to tidy up the search terms
    43174261 *
Note: See TracChangeset for help on using the changeset viewer.