Ticket #12659: 12659.diff
File 12659.diff, 4.6 KB (added by , 15 years ago) |
---|
-
wp-includes/canonical.php
155 155 156 156 $obj = $wp_query->get_queried_object(); 157 157 158 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) 159 && !is_wp_error($tax_url) && $redirect['query'] ) { 160 if ( is_category() ) { 161 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']); 162 } elseif ( is_tag() ) { 163 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']); 164 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: 165 $tax = get_taxonomy( $obj->taxonomy ); 166 if ( false !== $tax->query_var) 167 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); 168 else 169 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); 158 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { 159 if ( !empty($redirect['query']) ) { 160 if ( is_category() ) { 161 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']); 162 } elseif ( is_tag() ) { 163 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']); 164 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: 165 $tax = get_taxonomy( $obj->taxonomy ); 166 if ( false !== $tax->query_var) 167 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); 168 else 169 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); 170 } 170 171 } 171 172 172 $tax_url = parse_url($tax_url); 173 173 if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. 174 174 parse_str($tax_url['query'], $query_vars); … … 176 176 } else { // Taxonomy is accessable via a "pretty-URL" 177 177 $redirect['path'] = $tax_url['path']; 178 178 } 179 180 179 } 181 180 } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { 182 181 $category = get_term_by('slug', get_query_var('category_name'), 'category'); -
wp-includes/taxonomy.php
270 270 $wp_taxonomies = array(); 271 271 272 272 $defaults = array( 'hierarchical' => false, 273 'hierarchical_uri' => false, 273 274 'update_count_callback' => '', 274 275 'rewrite' => true, 275 276 'query_var' => $taxonomy, … … 295 296 'slug' => sanitize_title_with_dashes($taxonomy), 296 297 'with_front' => true, 297 298 )); 298 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term="); 299 if ( $args['hierarchical'] && $args['hierarchical_uri'] ) 300 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '.*?/?([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term="); 301 else 302 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term="); 299 303 $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']); 300 304 } 301 305 … … 2594 2598 $termlink = $wp_rewrite->get_extra_permastruct($taxonomy); 2595 2599 2596 2600 $slug = $term->slug; 2601 $t = get_taxonomy($taxonomy); 2597 2602 2598 2603 if ( empty($termlink) ) { 2599 $t = get_taxonomy($taxonomy);2600 2604 if ( $t->query_var ) 2601 2605 $termlink = "?$t->query_var=$slug"; 2602 2606 else 2603 2607 $termlink = "?taxonomy=$taxonomy&term=$slug"; 2604 2608 $termlink = home_url($termlink); 2605 2609 } else { 2606 $termlink = str_replace("%$taxonomy%", $slug, $termlink); 2610 if ( $t->hierarchical_uri ) { 2611 $hierarchical_slugs = array(); 2612 $ancestors = get_ancestors($term->term_id, $taxonomy); 2613 foreach ( (array)$ancestors as $ancestor ) { 2614 $ancestor_term = get_term($ancestor, $taxonomy); 2615 $hierarchical_slugs[] = $ancestor_term->slug; 2616 } 2617 $hierarchical_slugs = array_reverse($hierarchical_slugs); 2618 $hierarchical_slugs[] = $slug; 2619 $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink); 2620 } else { 2621 $termlink = str_replace("%$taxonomy%", $slug, $termlink); 2622 } 2607 2623 $termlink = home_url( user_trailingslashit($termlink, 'category') ); 2608 2624 } 2609 2625 return apply_filters('term_link', $termlink, $term, $taxonomy);