Make WordPress Core


Ignore:
Timestamp:
10/06/2010 10:40:30 AM (15 years ago)
Author:
scribu
Message:

Generalize taxonomy queries:

  • transform wp_tax_query() into WP_Object_Query::get_tax_sql()
  • create parse_tax_query() method in WP_Query
  • add doc-block for $tax_query and $meta_query

See #15032. See #12891.

File:
1 edited

Legend:

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

    r15712 r15731  
    531531
    532532    return $wpdb->get_col( $sql ); 
    533 }
    534 
    535 /*
    536  * Retrieve object_ids matching one or more taxonomy queries
    537  *
    538  * @since 3.1.0
    539  *
    540  * @param array $queries A list of taxonomy queries. A query is an associative array:
    541  *   'taxonomy' string|array The taxonomy being queried
    542  *   'terms' string|array The list of terms
    543  *   'field' string Which term field is being used. Can be 'term_id', 'slug' or 'name'
    544  *   'operator' string Can be 'IN' and 'NOT IN'
    545  *
    546  * @return array|WP_Error List of matching object_ids; WP_Error on failure.
    547  */
    548 function wp_tax_query( $queries ) {
    549     global $wpdb;
    550 
    551     $sql = array();
    552     foreach ( $queries as $query ) {
    553         if ( !isset( $query['include_children'] ) )
    554             $query['include_children'] = true;
    555         $query['do_query'] = false;
    556         $sql[] = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
    557     }
    558 
    559     if ( 1 == count( $sql ) )
    560         return $wpdb->get_col( $sql[0] );
    561 
    562     $r = "SELECT object_id FROM $wpdb->term_relationships WHERE 1=1";
    563     foreach ( $sql as $query )
    564         $r .= " AND object_id IN ($query)";
    565 
    566     return $wpdb->get_col( $r );
    567533}
    568534
Note: See TracChangeset for help on using the changeset viewer.