Changeset 5585

Show
Ignore:
Timestamp:
05/29/07 04:25:09 (1 year ago)
Author:
ryan
Message:

get_objects_in_term()

Files:

Legend:

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

    r5579 r5585  
    860860                $in_cats = " AND $wpdb->term_taxonomy.term_id IN ({$q['cat']}) "; 
    861861            if ( strlen($out_cats) > 0 ) { 
    862                 // TODO 
     862                // TODO use get_objects_in_term 
    863863                $ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)"); 
    864864                if ( is_array($ids) && count($ids > 0) ) { 
  • trunk/wp-includes/taxonomy.php

    r5567 r5585  
    365365 
    366366    return $tt_ids; 
     367} 
     368 
     369function get_objects_in_term( $terms, $taxonomies, $args = array() ) { 
     370    global $wpdb; 
     371 
     372    if ( !is_array( $terms) ) 
     373        $terms = array($terms); 
     374 
     375    if ( !is_array($taxonomies) ) 
     376        $taxonomies = array($taxonomies); 
     377 
     378    $defaults = array('order' => 'ASC'); 
     379    $args = wp_parse_args( $args, $defaults ); 
     380    extract($args); 
     381 
     382    $taxonomies = "'" . implode("', '", $taxonomies) . "'"; 
     383    $terms = "'" . implode("', '", $terms) . "'"; 
     384 
     385    $object_ids = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($in_terms) ORDER BY tr.object_id $order"); 
     386 
     387    if ( ! $object_ids ) 
     388        return array(); 
     389 
     390    return $object_ids; 
    367391} 
    368392