Make WordPress Core


Ignore:
Timestamp:
05/23/2007 07:15:10 AM (18 years ago)
Author:
ryan
Message:

Start moving link categories to taxonomy. see #4189

File:
1 edited

Legend:

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

    r5522 r5523  
    183183 * @return array The requested term data.           
    184184 */
    185 function get_object_terms($object_id, $taxonomy) {
     185function get_object_terms($object_id, $taxonomy, $args = array()) {
    186186    global $wpdb;
    187187    $taxonomies = ($single_taxonomy = !is_array($taxonomy)) ? array($taxonomy) : $taxonomy;
    188188    $object_ids = ($single_object = !is_array($object_id)) ? array($object_id) : $object_id;
    189189
     190    $defaults = array('orderby' => 'name', 'order' => 'ASC', 'get' => 'everything');
     191    $args = wp_parse_args( $args, $defaults );
     192    extract($args);
     193
     194    if ( 'count' == $orderby )
     195        $orderby = 'tt.count';
     196    else if ( 'name' == $orderby )
     197        $orderby = 't.name';
     198
    190199    $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    191200    $object_ids = implode(', ', $object_ids);
    192201
    193     if ( $taxonomy_data = $wpdb->get_results("SELECT t.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) ORDER BY t.name") ) {
    194         if ($single_taxonomy && $single_object) {
    195             // Just one kind of taxonomy for one object.
    196             return $taxonomy_data;
    197         } else {
    198             foreach ($taxonomy_data as $data) {
    199                 if ($single_taxonomy) {
    200                     // Many objects, one taxonomy type.
    201                     $return[$data->object_id][] = $data;
    202                 } elseif ($single_object) {
    203                     // One object, many taxonomies.
    204                     $return[$data->taxonomy][] = $data;
    205                 } else {
    206                     // Many objects, many taxonomies.
    207                     $return[$data->object_id][$data->taxonomy][] = $data;
    208                 }
     202    if ( 'everything' == $get )
     203        $select_this = 't.*';
     204    else if ( 'ids' == $get )
     205        $select_this = 't.term_id';
     206
     207    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) ORDER BY $orderby $order";
     208
     209    if ( 'everything' == $get )
     210        $taxonomy_data = $wpdb->get_results($query);
     211    else if ( 'ids' == $get )
     212        $taxonomy_data = $wpdb->get_col($query);
     213
     214    if ( ! $taxonomy_data )
     215        return array();
     216
     217    if ($single_taxonomy && $single_object) {
     218        // Just one kind of taxonomy for one object.
     219        return $taxonomy_data;
     220    } else {
     221        foreach ($taxonomy_data as $data) {
     222            if ($single_taxonomy) {
     223                // Many objects, one taxonomy type.
     224                $return[$data->object_id][] = $data;
     225            } elseif ($single_object) {
     226                // One object, many taxonomies.
     227                $return[$data->taxonomy][] = $data;
     228            } else {
     229                // Many objects, many taxonomies.
     230                $return[$data->object_id][$data->taxonomy][] = $data;
    209231            }
    210             return $return;         
    211         }
    212     } else {
    213         return array();
     232        }
     233        return $return;         
    214234    }
    215235}
     
    224244    $defaults = array('orderby' => 'name', 'order' => 'ASC',
    225245        'hide_empty' => true, 'exclude' => '', 'include' => '',
    226         'number' => '');
     246        'number' => '', 'get' => 'everything');
    227247    $args = wp_parse_args( $args, $defaults );
    228248    $args['number'] = (int) $args['number'];
     
    279299        $number = '';
    280300
    281     $terms = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number");
     301    if ( 'everything' == $get )
     302        $select_this = 't.*, tt.*';
     303    else if ( 'ids' == $get )
     304        $select_this = 't.term_id';
     305
     306    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
     307
     308    if ( 'everything' == $get )
     309        $terms = $wpdb->get_results($query);
     310    else if ( 'ids' == $get )
     311        $terms = $wpdb->get_col($query);
    282312
    283313    if ( empty($terms) )
Note: See TracChangeset for help on using the changeset viewer.