Make WordPress Core

Changeset 5585


Ignore:
Timestamp:
05/29/2007 04:25:09 AM (16 years ago)
Author:
ryan
Message:

get_objects_in_term()

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.