Rewrite permalink to include multiple taxonomies

I've seen similar questions posted before but they don't seem to quite fit my problem.

I have a post type called product and I have 2 taxonomies, product_cat and location

I want archive pages that combine both these taxonomies which would be structured like this /product/product_cat/location

I know this can be done with rewrites but I can't figure out how to make it work.

Update

I've achieved this to an extent using

  add_rewrite_rule( '^art-classes/([^/]*)/([^/]*)/?',
                 'index.php?product_cat=$matches[1]location=$matches[2]',
                 'top' );

But now my single product page won't load. it just loads the archive page still. Something wrong with my regex?

Topic regex rewrite-rules taxonomy archives Wordpress

Category Web


function custom_rewrite_rules() {
 add_rewrite_rule( '^art-classes/([^/]*)/([^/]*)/?$',
                 'index.php?product_cat=$matches[1]&location=$matches[2]',
                 'top' );

}
add_action('init', 'custom_rewrite_rules');

The $ at the end did the job. Not sure why.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.