Cray
Cray

Reputation: 5513

WooCommerce: Add content to archive with multiple filter attributes

I want to add some SEO content to some of my archives.

For example:

I have a category called "Sportcars". It's easy to add some content thereby adding it to the category archive page.

But I also want some content on the archive where I filter by "Sportcars" (product category), "Cabrio" (attribute) and "black" (attribute).

The URL looks something like this:

domain.com/products/sportcars/?filter_type=cabrio&filter_color=black

Is there any way to address such an archive?

I'm thinking about something to do with the URL parameters. But I couldn't figure out a good solution.

Maybe there is a way to rewrite the URL to add some ID's for the category and the filters and use them to build a custom post type with a slug based on ID's. I can then search for the post type and display. it's content. But maybe the filters are in different orders sometimes!?

For example here's what I mean:

domain.com/products/100/?filter_type=200&filter_color=300

Now the Custom Post Type slug is something like this (not visible in the frontend):

/seo-content/100-200-300/

Is this possible? Or is there a better way? I searched a lot and couldn't find anything.

Upvotes: 0

Views: 462

Answers (1)

kaize
kaize

Reputation: 811

An easy way to get the job done without messing with custom slugs and archives is to use a php if statement in your archive checking if the values posted is "cabrio" & "black" like this:

$filter_type = $_GET[filter_type];
$filter_color = $_GET[filter_color];
if ( (isset($filter_type) == 'cabrio') && (isset($filter_color) == 'black') ) 
{
//your content here
} else {
//your content here
}

Upvotes: 1

Related Questions