Make WordPress Core


Ignore:
Timestamp:
11/09/2010 11:30:35 PM (16 years ago)
Author:
scribu
Message:

Make get_tax_sql() a standalone function. See #15032

File:
1 edited

Legend:

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

    r16266 r16267  
    7373
    7474        /*
    75          * Used internally to generate an SQL string for searching across multiple taxonomies
    76          *
    77          * @access protected
    78          * @since 3.1.0
    79          *
    80          * @param array $tax_query List of taxonomy queries. A single taxonomy query is an associative array:
    81          * - 'taxonomy' string|array The taxonomy being queried
    82          * - 'terms' string|array The list of terms
    83          * - 'field' string (optional) Which term field is being used.
    84          *              Possible values: 'term_id', 'slug' or 'name'
    85          *              Default: 'slug'
    86          * - 'operator' string (optional)
    87          *              Possible values: 'IN' and 'NOT IN'.
    88          *              Default: 'IN'
    89          * - 'include_children' bool (optional) Whether to include child terms.
    90          *              Default: true
    91          *
    92          * @param string $object_id_column
    93          * @return string
    94          */
    95         function get_tax_sql( $tax_query, $object_id_column ) {
    96                 global $wpdb;
    97 
    98                 $sql = array();
    99                 foreach ( $tax_query as $query ) {
    100                         if ( !isset( $query['include_children'] ) )
    101                                 $query['include_children'] = true;
    102 
    103                         $query['do_query'] = false;
    104 
    105                         $sql_single = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
    106 
    107                         if ( empty( $sql_single ) )
    108                                 return ' AND 0 = 1';
    109 
    110                         $sql[] = $sql_single;
    111                 }
    112 
    113                 if ( 1 == count( $sql ) ) {
    114                         $ids = $wpdb->get_col( $sql[0] );
    115                 } else {
    116                         $r = "SELECT object_id FROM $wpdb->term_relationships WHERE 1=1";
    117                         foreach ( $sql as $query )
    118                                 $r .= " AND object_id IN ($query)";
    119 
    120                         $ids = $wpdb->get_col( $r );
    121                 }
    122 
    123                 if ( !empty( $ids ) )
    124                         return " AND $object_id_column IN(" . implode( ', ', $ids ) . ")";
    125                 else
    126                         return ' AND 0 = 1';
    127         }
    128 
    129         /*
    13075         * Used internally to generate an SQL string for searching across multiple columns
    13176         *
Note: See TracChangeset for help on using the changeset viewer.