## url rewriting – Taxonomy URL rewrite whilst keeping filtered posts?

Question

I’m trying to essentially filter Woocommerce products by looping through the terms and allowing the user to click the permalink which will take them to a page which filters the products based on what was clicked:

if ( is_array( $brands ) ) { echo '<div class="filters__brand"> <div class="filters__tab" data-filter-toggle=""> <span class="filters__iden">Brands</span> <span class="filters__close"></span> </div> <div class="filters__itemwrapper">'; foreach ($brands as $brand ){ echo '<div><a style="color:black" href="' . htmlentities( add_query_arg( 'pwb-brand',$brand->slug, $page_link ) ) . '">' .$brand->name . '</a></div>';
}
echo '<li><a href="' . htmlentities( remove_query_arg( 'pwb-brand', $page_link ) ) . '">None</a></li>'; echo '</div> </div>'; } if ( is_array($categories ) ) {
echo '<div class="filters__cat">
<div class="filters__tab" data-filter-toggle="">
<span class="filters__iden">Type</span>
<span class="filters__close"></span>
</div>
<ul class="filters__itemwrapper">';
foreach ( $categories as$category ) {
echo '<li><a style="color:black" href="' . htmlentities( add_query_arg( 'product_cat', $category->slug,$page_link ) ) . '">' . $category->name . '</a></li>'; } echo '<li><a href="' . htmlentities( remove_query_arg( 'product_cat',$page_link ) ) . '">None</a></li>';
echo '</ul></div>';
} ?>


This works fine.

However, what I need to achieve is instead of the URL being:

/our-products/?pwb-brand=example-brand

I’d like to use WP’s rewriting functionality to essentially make it:

/our-products/pwb-brand/example-brand

While looking for solutions online, and adding a couple of different rewriting functions to my functions.php file I managed to get my local build to navigate to:

/our-products/pwb-brand/example-brand

But instead of the filtered products being displayed it was rendering all products. So it looks like the filter doesn’t work when using rewrites? I could be mistaken however.

Any help would be appreciated.

0
11 months 2021-09-10T06:13:24-05:00 0 Answers 0 views 0