Changes from branches/3.1/wp-includes/canonical.php at r18015 to trunk/wp-includes/canonical.php at r18254
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/canonical.php
r18015 r18254 153 153 154 154 $obj = $wp_query->get_queried_object(); 155 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) && !empty($redirect['query'])) {155 if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { 156 156 if ( !empty($redirect['query']) ) { 157 // Strip taxonomy query vars off the url. 158 $qv_remove = array( 'term', 'taxonomy'); 157 159 if ( is_category() ) { 158 $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']); 160 $qv_remove[] = 'category_name'; 161 $qv_remove[] = 'cat'; 159 162 } elseif ( is_tag() ) { 160 $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']); 161 } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: 162 $tax = get_taxonomy( $obj->taxonomy ); 163 if ( false !== $tax->query_var) 164 $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); 165 else 166 $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); 163 $qv_remove[] = 'tag'; 164 $qv_remove[] = 'tag_id'; 165 } else { // Custom taxonomies will have a custom query var, remove those too: 166 $tax_obj = get_taxonomy( $obj->taxonomy ); 167 if ( false !== $tax_obj->query_var ) 168 $qv_remove[] = $tax_obj->query_var; 169 } 170 171 $rewrite_vars = array_diff( array_keys($wp_query->query), array_keys($_GET) ); 172 173 if ( !array_diff($rewrite_vars, array_keys($_GET)) ) { // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET 174 $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']); //Remove all of the per-tax qv's 175 176 // Create the destination url for this taxonomy 177 $tax_url = parse_url($tax_url); 178 if ( ! empty($tax_url['query']) ) { // Taxonomy accessable via ?taxonomy=..&term=.. or any custom qv.. 179 parse_str($tax_url['query'], $query_vars); 180 $redirect['query'] = add_query_arg($query_vars, $redirect['query']); 181 } else { // Taxonomy is accessable via a "pretty-URL" 182 $redirect['path'] = $tax_url['path']; 183 } 184 185 } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite 186 foreach ( $qv_remove as $_qv ) { 187 if ( isset($rewrite_vars[$_qv]) ) 188 $redirect['query'] = remove_query_arg($_qv, $redirect['query']); 189 } 167 190 } 168 191 } 169 $tax_url = parse_url($tax_url); 170 if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=.. 171 parse_str($tax_url['query'], $query_vars); 172 $redirect['query'] = add_query_arg($query_vars, $redirect['query']); 173 } else { // Taxonomy is accessable via a "pretty-URL" 174 $redirect['path'] = $tax_url['path']; 175 } 192 176 193 } 177 194 } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
Note: See TracChangeset
for help on using the changeset viewer.