admin管理员组

文章数量:1122826

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?

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?

Share Improve this question edited Aug 31, 2016 at 19:05 Luke Seall asked Aug 31, 2016 at 13:16 Luke SeallLuke Seall 3303 silver badges17 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0
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.

本文标签: taxonomyRewrite permalink to include multiple taxonomies