Last active
August 29, 2015 13:56
-
-
Save dawnerd/8854841 to your computer and use it in GitHub Desktop.
Allows category and product to share a same base in woocommerce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('request', function( $request ) { | |
$tax_qv = 'product_cat'; | |
$cpt_name = 'product'; | |
if(!empty( $request[$tax_qv])) { | |
$slug = basename($request[$tax_qv]); | |
// if this would generate a 404 | |
if(!get_term_by('slug', $slug, $tax_qv)) { | |
// set the correct query vars | |
$request['name'] = $slug; | |
$request['post_type'] = $cpt_name; | |
unset($request[$tax_qv]); | |
} | |
} | |
return $request; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment