Changeset 5592

Show
Ignore:
Timestamp:
05/29/07 16:52:31 (1 year ago)
Author:
ryan
Message:

Use taxonomy instead of post2cat. see #4189

Files:

Legend:

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

    r5590 r5592  
    360360    $join = ''; 
    361361    if ( $in_same_cat ) { 
    362         $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id "; 
    363         $cat_array = get_the_category($post->ID); 
    364         $join .= ' AND (category_id = ' . intval($cat_array[0]->term_id); 
     362        $join = " INNER JOIN $wpdb->term_relationships AS tr ON $wpdb->posts.ID = tr.object_id "; 
     363        $cat_array = get_object_terms($post->ID, 'category', 'fields=tt_ids'); 
     364        $join .= ' AND (tr.term_taxonomy_id = ' . intval($cat_array[0]); 
    365365        for ( $i = 1; $i < (count($cat_array)); $i++ ) { 
    366             $join .= ' OR category_id = ' . intval($cat_array[$i]->term_id); 
     366            $join .= ' OR tr.term_taxonomy_id = ' . intval($cat_array[$i]); 
    367367        } 
    368368        $join .= ')'; 
     
    372372    if ( !empty($excluded_categories) ) { 
    373373        $blah = explode(' and ', $excluded_categories); 
    374         foreach ( $blah as $category ) { 
    375             $category = intval($category); 
    376             $sql_cat_ids = " OR pc.category_ID = '$category'"; 
    377         } 
    378         $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id=p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID"); 
     374        $posts_in_ex_cats = get_objects_in_term($blah, 'category'); 
    379375        $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')'; 
    380376    } 
     
    397393    $join = ''; 
    398394    if ( $in_same_cat ) { 
    399         $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id "; 
    400         $cat_array = get_the_category($post->ID); 
    401         $join .= ' AND (category_id = ' . intval($cat_array[0]->term_id); 
     395        $join = " INNER JOIN $wpdb->term_relationships AS tr ON $wpdb->posts.ID = tr.object_id "; 
     396        $cat_array = get_object_terms($post->ID, 'category', 'fields=tt_ids'); 
     397        $join .= ' AND (tr.term_taxonomy_id = ' . intval($cat_array[0]); 
    402398        for ( $i = 1; $i < (count($cat_array)); $i++ ) { 
    403             $join .= ' OR category_id = ' . intval($cat_array[$i]->term_id); 
     399            $join .= ' OR tr.term_taxonomy_id = ' . intval($cat_array[$i]); 
    404400        } 
    405401        $join .= ')'; 
     
    409405    if ( !empty($excluded_categories) ) { 
    410406        $blah = explode(' and ', $excluded_categories); 
    411         foreach ( $blah as $category ) { 
    412             $category = intval($category); 
    413             $sql_cat_ids = " OR pc.category_ID = '$category'"; 
    414         } 
    415         $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID from $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id = p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID"); 
     407        $posts_in_ex_cats = get_objects_in_term($blah, 'category'); 
    416408        $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')'; 
    417409    } 
  • trunk/wp-includes/post.php

    r5586 r5592  
    231231 
    232232    $query  = "SELECT DISTINCT * FROM $wpdb->posts "; 
    233     $query .= empty( $category ) ? '' : ", $wpdb->post2cat ";  
     233    $query .= empty( $category ) ? '' : ", $wpdb->term_relationships, $wpdb->term_taxonomy ";  
    234234    $query .= empty( $meta_key ) ? '' : ", $wpdb->postmeta "; 
    235235    $query .= " WHERE 1=1 "; 
     
    237237    $query .= empty( $post_status ) ? '' : "AND post_status = '$post_status' "; 
    238238    $query .= "$exclusions $inclusions " ; 
    239     $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") "; 
     239    $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = " . $category. ") "; 
    240240    $query .= empty( $post_parent ) ? '' : "AND $wpdb->posts.post_parent = '$post_parent' "; 
    241241    $query .= empty( $meta_key ) | empty($meta_value)  ? '' : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )"; 
     
    16961696 
    16971697function update_post_category_cache($post_ids) { 
    1698     global $wpdb, $category_cache, $tag_cache, $blog_id; 
     1698    global $wpdb, $term_cache, $blog_id; 
    16991699    // TODO 
    17001700    return; 
     
    17091709    for ( $i = 0; $i < $count; $i++ ) { 
    17101710        $post_id = (int) $post_id_array[ $i ]; 
    1711         if ( isset( $category_cache[$blog_id][$post_id] ) ) { 
     1711        if ( isset( $term_cache[$blog_id][$post_id] ) ) { 
    17121712            unset( $post_id_array[ $i ] ); 
    17131713            continue; 
     
    17161716    if ( count( $post_id_array ) == 0 ) 
    17171717        return; 
    1718     $post_id_list = join( ',', $post_id_array ); // with already cached stuff removed 
    1719  
    1720     $dogs = $wpdb->get_results("SELECT post_id, category_id, rel_type FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)"); 
     1718 
     1719    $dogs = get_object_terms($post_id_array, array('category', 'post_tag')); 
    17211720 
    17221721    if ( empty($dogs) ) 
     
    17241723 
    17251724    foreach ($dogs as $catt) { 
    1726         if ( 'category' == $catt->rel_type ) 
    1727             $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 
    1728         elseif ( 'tag' == $catt->rel_type ) 
    1729             $tag_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 
     1725        $term_cache[$blog_id][$catt->post_id][$catt->taxonomy][$catt->category_id] = &get_category($catt->category_id); 
    17301726    } 
    17311727} 
    17321728 
    17331729function update_post_caches(&$posts) { 
    1734     global $post_cache, $category_cache, $post_meta_cache, $tag_cache
     1730    global $post_cache
    17351731    global $wpdb, $blog_id; 
    17361732 
  • trunk/wp-includes/query.php

    r5585 r5592  
    850850                $in = (strpos($cat, '-') !== false) ? false : true; 
    851851                $cat = trim($cat, '-'); 
     852                // TODO make an array, not a string, for out_cats.  use get_term_children() 
    852853                if ( $in ) 
    853854                    $in_cats .= "$cat, " . get_category_children($cat, '', ', '); 
     
    861862            if ( strlen($out_cats) > 0 ) { 
    862863                // TODO use get_objects_in_term 
    863                 $ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)"); 
     864                $ids = get_objects_in_terms($out_cats, 'category'); 
    864865                if ( is_array($ids) && count($ids > 0) ) { 
    865866                    foreach ( $ids as $id ) 
  • trunk/wp-includes/taxonomy.php

    r5585 r5592  
    379379    $args = wp_parse_args( $args, $defaults ); 
    380380    extract($args); 
     381 
     382    $terms = array_map('intval', $terms); 
    381383 
    382384    $taxonomies = "'" . implode("', '", $taxonomies) . "'";