Make WordPress Core

Ticket #14699: better-tax-sql.diff

File better-tax-sql.diff, 1.2 KB (added by misterbisson, 16 years ago)

aliases the term_taxonomy and term_relationship tables to avoid conflicting with other joins

  • query.php

     
    20472047                                                $children = get_term_children($term->term_id, $taxonomy);
    20482048                                                $term_ids = array_merge($term_ids, $children);
    20492049                                        }
     2050
     2051                                        $join .= " INNER JOIN $wpdb->term_relationships tax_tr ON ($wpdb->posts.ID = tax_tr.object_id) INNER JOIN $wpdb->term_taxonomy tax_tt ON (tax_tr.term_taxonomy_id = tax_tt.term_taxonomy_id) ";
     2052                                        $whichcat .= " AND tax_tt.taxonomy = '$taxonomy' ";
     2053                                        $in_cats = "'" . implode("', '", $term_ids) . "'";
     2054                                        $whichcat .= "AND tax_tt.term_id IN ($in_cats)";
     2055                                        $groupby = "{$wpdb->posts}.ID";
    20502056                                }
    2051                                 $post_ids = get_objects_in_term($term_ids, $taxonomy);
    2052                                 if ( !is_wp_error($post_ids) && !empty($post_ids) ) {
    2053                                         $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
    2054                                         if ( empty($post_type) ) {
    2055                                                 $post_type = 'any';
    2056                                                 $post_status_join = true;
    2057                                         } elseif ( in_array('attachment', (array)$post_type) ) {
    2058                                                 $post_status_join = true;
    2059                                         }
    2060                                 } else {
    2061                                         $whichcat = " AND 0 ";
    2062                                 }
    20632057                        }
    20642058                }
    20652059
     2060
    20662061                // Author/user stuff
    20672062
    20682063                if ( empty($q['author']) || ($q['author'] == '0') ) {