Wordpress - Combining Multiple Taxonomies in one URL
This rewrite rule should work (assuming "brand" and "type" are the taxonomy registered names):
function custom_rewrite_rules() {
add_rewrite_rule('^brand/(.*)/type/(.*)?', 'index.php?brand=$matches[1]&type=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_rules');
Remember to flush the rewirte rules after saving this code in your site.
Then you will need to hook in several places to fix things. For example, you may need to hook wp_title
to generate the correct title for the document, for example "HP Printers" instead or just "HP", as this won't be handle automatically by WordPress. I can't give a exhaustive list of things you will need to fix.
While digging up to answer this one, I found here the following rewrite function:
function eg_add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
'user/(profession|city)/(.+?)/(profession|city)/(.+?)/?$' => 'index.php?post_type=eg_event&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) . '&' . $wp_rewrite->preg_index(3) . '=' . $wp_rewrite->preg_index(4),
'user/(profession|city)/(.+)/?$' => 'index.php?post_type=eg_event&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );
this function takes a url like: example.com/user/profession/designer,knight/city/athens,gotham/ and converts it in variables:
$proffession = "designer,knight";
$city = "athens,gotham";
which can be used in the taxonomy.php
More info: https://stackoverflow.com/a/34624138/5594521
Working demo: http://playground.georgemanousarides.com/
Hope it helps!