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']); |
| 162 | $qv_remove += array( 'tag', 'tag_id'); |
| 163 | } else { // Custom taxonomies will have a custom query var, remove those too: |
| 164 | $tax_obj = get_taxonomy( $obj->taxonomy ); |
| 165 | if ( false !== $tax_obj->query_var) |
| 166 | $qv_remove += array($tax_obj->query_var); |
173 | | $tax_url = parse_url($tax_url); |
174 | | if ( ! empty($tax_query_vars) ) { |
175 | | foreach ( array( 'taxonomy', 'term', $tax_obj->query_var ) as $qv ) { |
176 | | if ( !empty($wp_query->query[$qv]) ) |
177 | | $redirect['query'] = add_query_arg($qv, $wp_query->query[$qv], $redirect['query']); |
| 171 | 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 |
| 172 | $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']); //Remove all of the per-tax qv's |
| 173 | |
| 174 | // Create the destination url for this taxonomy |
| 175 | $tax_url = parse_url($tax_url); |
| 176 | if ( ! empty($tax_url['query']) ) { // Taxonomy accessable via ?taxonomy=..&term=.. or any custom qv.. |
| 177 | parse_str($tax_url['query'], $query_vars); |
| 178 | $redirect['query'] = add_query_arg($query_vars, $redirect['query']); |
| 179 | } else { // Taxonomy is accessable via a "pretty-URL" |
| 180 | $redirect['path'] = $tax_url['path']; |
| 181 | } |
| 182 | |
| 183 | } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite |
| 184 | foreach ( $qv_remove as $_qv ) { |
| 185 | if ( isset($rewrite_vars[$_qv]) ) |
| 186 | $redirect['query'] = remove_query_arg($_qv, $redirect['query']); |
| 187 | } |