I’m creating a complex site with a product catalog with two custom taxonomies. They are Brands and Types.
Brands
– Canon
– Toshiba
– HP
Types
– Printers
– Scanners
– Multifunction
I need a page that finds all products that are any combination of one brand and one type. The brand is the more important of the two, so it should be filtered as Brand -> Type (although it’d be ideal if this was interchangeable).
I can do this by modifying the query based off of a parameter I add to the end of the URL. For example, this URL could be one of the following:
- http://www.example.com/brand/canon/?type=printers
- http://www.example.com/brand/canon/?type=scanners
- http://www.example.com/brand/canon/?type=multifunction
- http://www.example.com/brand/toshiba/?type=printers
- http://www.example.com/brand/toshiba/?type=scanners
- http://www.example.com/brand/toshiba/?type=multifunction
- http://www.example.com/brand/hp/?type=printers
- http://www.example.com/brand/hp/?type=scanners
- http://www.example.com/brand/hp/?type=multifunction
But I’ve been told this isn’t great for SEO purposes. Ideally, I’d like the URL to be structured as http://www.example.com/brand/type/. This would result in URLs like:
- http://www.example.com/canon/printers
- http://www.example.com/canon/scanners
- http://www.example.com/canon/multifunction
- http://www.example.com/toshiba/printers
- http://www.example.com/toshiba/scanners
- http://www.example.com/toshiba/multifunction
- http://www.example.com/hp/printers
- http://www.example.com/hp/scanners
- http://www.example.com/hp/multifunction
Yes, I know I could set up sub-cateogires for each product type under each brand, but I also need to be able to view all products under each product type irrelevant of brand.
By the way, if the URL needs to be a little more complex (i.e. /brand/hp/type/multifunction/) that’s better than nothing.
Is there some trickery with permalinks I could do to get the links to be structured the way I need them to be?
UPDATE 10/23/15: I just spent an hour trying to diagnose why this stopped working on the site I had built. Turns out I was overriding the default query with a custom one on one of the taxonomy archive templates. To combat this, you can do the following:
<?php $tax_query = $wp_query->query_vars; ?>
<?php
if ($tax_query["types"] && $tax_query["brands"]) {
// default query stuff here
} else {
// custom query stuff here
}
?>