Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_detect_tax_combination( $request ) {
- global $wp, $wpdb;
- $taxonomies = array(
- 'fuel',
- );
- $taxonomies_2 = array(
- 'manufacturer'
- );
- // Parse the URI
- // URL Format: taxonomy_term/taxonomy_2_term
- preg_match( '/^([^\/]+)(?:\/([^\/]+))?(?:\/page\/([\d]+))?/', $wp->request, $parts );
- if ( ! empty( $parts[1] ) && ! empty( $parts[2] ) ) {
- // Get term #1
- $term = $wpdb->get_row( $wpdb->prepare( "
- SELECT * FROM {$wpdb->terms} AS t
- LEFT JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
- WHERE t.slug = %s", sanitize_title( $parts[1] ) ) );
- // Get term #2
- $term_2 = $wpdb->get_row( $wpdb->prepare( "
- SELECT * FROM {$wpdb->terms} AS t
- LEFT JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
- WHERE slug = %s", sanitize_title( $parts[2] ) ) );
- // Filter the query if both post type & term were found
- if ( ! empty( $term ) && in_array( $term->taxonomy, $taxonomies ) && ! empty( $term_2 ) && in_array( $term_2->taxonomy, $taxonomies_2 ) ) {
- $request = array(
- $term->taxonomy => $term->slug,
- $term_2->taxonomy => $term_2->slug,
- 'do_not_redirect' => 1,
- 'new_canonical' => 1
- );
- // Disable inbuilt canonical redirect
- remove_action( 'template_redirect', 'wp_old_slug_redirect' );
- remove_action( 'template_redirect', 'redirect_canonical' );
- // Support pagination
- if ( ! empty( $parts[3] ) ) {
- $request['paged'] = $parts[3];
- }
- }
- }
- return $request;
- }
- add_filter( 'request', 'pm_detect_tax_combination', 99 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement