Make WordPress Core


Ignore:
Timestamp:
05/29/2007 04:52:31 PM (18 years ago)
Author:
ryan
Message:

Use taxonomy instead of post2cat. see #4189

File:
1 edited

Legend:

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