Changeset 5592
- Timestamp:
- 05/29/2007 04:52:31 PM (16 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/link-template.php
r5590 r5592 360 360 $join = ''; 361 361 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]); 365 365 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]); 367 367 } 368 368 $join .= ')'; … … 372 372 if ( !empty($excluded_categories) ) { 373 373 $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'); 379 375 $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')'; 380 376 } … … 397 393 $join = ''; 398 394 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]); 402 398 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]); 404 400 } 405 401 $join .= ')'; … … 409 405 if ( !empty($excluded_categories) ) { 410 406 $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'); 416 408 $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')'; 417 409 } -
trunk/wp-includes/post.php
r5586 r5592 231 231 232 232 $query = "SELECT DISTINCT * FROM $wpdb->posts "; 233 $query .= empty( $category ) ? '' : ", $wpdb-> post2cat";233 $query .= empty( $category ) ? '' : ", $wpdb->term_relationships, $wpdb->term_taxonomy "; 234 234 $query .= empty( $meta_key ) ? '' : ", $wpdb->postmeta "; 235 235 $query .= " WHERE 1=1 "; … … 237 237 $query .= empty( $post_status ) ? '' : "AND post_status = '$post_status' "; 238 238 $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. ") "; 240 240 $query .= empty( $post_parent ) ? '' : "AND $wpdb->posts.post_parent = '$post_parent' "; 241 241 $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' )"; … … 1696 1696 1697 1697 function update_post_category_cache($post_ids) { 1698 global $wpdb, $ category_cache, $tag_cache, $blog_id;1698 global $wpdb, $term_cache, $blog_id; 1699 1699 // TODO 1700 1700 return; … … 1709 1709 for ( $i = 0; $i < $count; $i++ ) { 1710 1710 $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] ) ) { 1712 1712 unset( $post_id_array[ $i ] ); 1713 1713 continue; … … 1716 1716 if ( count( $post_id_array ) == 0 ) 1717 1717 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')); 1721 1720 1722 1721 if ( empty($dogs) ) … … 1724 1723 1725 1724 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); 1730 1726 } 1731 1727 } 1732 1728 1733 1729 function update_post_caches(&$posts) { 1734 global $post_cache , $category_cache, $post_meta_cache, $tag_cache;1730 global $post_cache; 1735 1731 global $wpdb, $blog_id; 1736 1732 -
trunk/wp-includes/query.php
r5585 r5592 850 850 $in = (strpos($cat, '-') !== false) ? false : true; 851 851 $cat = trim($cat, '-'); 852 // TODO make an array, not a string, for out_cats. use get_term_children() 852 853 if ( $in ) 853 854 $in_cats .= "$cat, " . get_category_children($cat, '', ', '); … … 861 862 if ( strlen($out_cats) > 0 ) { 862 863 // 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'); 864 865 if ( is_array($ids) && count($ids > 0) ) { 865 866 foreach ( $ids as $id ) -
trunk/wp-includes/taxonomy.php
r5585 r5592 379 379 $args = wp_parse_args( $args, $defaults ); 380 380 extract($args); 381 382 $terms = array_map('intval', $terms); 381 383 382 384 $taxonomies = "'" . implode("', '", $taxonomies) . "'";
Note: See TracChangeset
for help on using the changeset viewer.