Make WordPress Core


Ignore:
Timestamp:
03/26/2008 06:37:19 AM (17 years ago)
Author:
ryan
Message:

Taxonomy links and template tags from andy. see #6357

File:
1 edited

Legend:

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

    r7511 r7520  
    681681            if ( empty($qv['taxonomy']) || empty($qv['term']) ) {
    682682                $this->is_tax = false;
     683                foreach ( $GLOBALS['wp_taxonomies'] as $t ) {
     684                    if ( isset($t->query_var) && '' != $qv[$t->query_var] ) {
     685                        $this->is_tax = true;
     686                        break;
     687                    }
     688                }
    683689            } else {
    684690                $this->is_tax = true;
     
    11471153        // Taxonomies
    11481154        if ( $this->is_tax ) {
    1149             $terms = get_terms($q['taxonomy'], array('slug'=>$q['term']));
    1150             foreach ( $terms as $term )
    1151                 $term_ids[] = $term->term_id;
    1152             $post_ids = get_objects_in_term($term_ids, $q['taxonomy']);
    1153 
    1154             if ( count($post_ids) ) {
    1155                 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
    1156                 $post_type = 'any';
    1157                 $q['post_status'] = 'publish';
    1158                 $post_status_join = true;
     1155            if ( '' != $q['taxonomy'] ) {
     1156                $taxonomy = $q['taxonomy'];
     1157                $tt[$taxonomy] = $q['term'];
     1158                $terms = get_terms($q['taxonomy'], array('slug'=>$q['term']));
    11591159            } else {
    1160                 $whichcat = " AND 0 = 1";
     1160                foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
     1161                    if ( isset($t->query_var) && '' != $q[$t->query_var] ) {
     1162                        $terms = get_terms($taxonomy, array('slug'=>$q[$t->query_var]));
     1163                        if ( !is_wp_error($terms) )
     1164                            break;
     1165                    }
     1166                }
     1167            }
     1168            if ( is_wp_error($terms) || empty($terms) ) {
     1169                $whichcat = " AND 0 ";
     1170            } else {
     1171                foreach ( $terms as $term )
     1172                    $term_ids[] = $term->term_id;
     1173                $post_ids = get_objects_in_term($term_ids, $taxonomy);
     1174                if ( !is_wp_error($post_ids) && count($post_ids) ) {
     1175                    $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
     1176                    $post_type = 'any';
     1177                    $q['post_status'] = 'publish';
     1178                    $post_status_join = true;
     1179                } else {
     1180                    $whichcat = " AND 0 ";
     1181                }
    11611182            }
    11621183        }
     
    12971318            }
    12981319            if ( $post_status_join ) {
    1299                 $join .= " INNER JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";
     1320                $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";
    13001321                foreach ( $statuswheres as $index => $statuswhere )
    13011322                    $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))";
Note: See TracChangeset for help on using the changeset viewer.