I'm facing an issue when I try to filter custom post type archive by category.
I want to filter the shop of woocommerce by multiple categories, so I made a widget that display a form with all categories with a checkbox for each one.
The HTMl for this form is :
<form method="get">
<?php foreach($cats as $cat) : ?>
<p>
<input
style="margin-bottom: 0;"
type="checkbox"
id="<?php echo $cat->slug?>"
name="product_cat[]"
value="<?php echo $cat->slug?>">
<label style="margin: 5px 0 0 0; color: #777;"
for="<?php echo $cat->slug?>" >
<?php echo $cat->name; ?> (<?php echo $cat->count ?>)
</label>
</p>
<?php endforeach; ?>
<button class="button primary" style="margin-top: 20px;" type="submit">
<?php _e('Filtrer', 'themedomain');?>
</button>
</form>
When I check one or more checkbox and submit the form i get this url
http://example.com/shop/?product_cat%5B%5D=chauffageclimatisation&product_cat%5B%5D=essencegaz
It seems great to me but i get this error message and no post is displaying :
Warning: urlencode() expects parameter 1 to be string, array given in /path/to/website/wp-includes/formatting.php on line 4791
I'm pretty sure that this must be working because i've done it at my previous job but I can't access code to check that. Can someone help me with it ?
I also know that WordPress automatically filter post if you add terms separate with ','
in the query, like :
http://example.com/shop/?product_catchauffageclimatisation,essencegaz
But I don't know how to get this result with checkbox.