Forum
Filtering products with two filters
Suppose you want to filter by category name and you want stock level > 1. How'd you go about doing that with functions or templates?
Suppose you want to filter by category name and you want stock level > 1. How'd you go about doing that with functions or templates?
If you use the function (i.e. https://docs.grabaperch.com/functions/shop/products/perch-shop-products/) you can set the
category
option and thefilter
option.Also, check out the
perch_content_custom
orperch_collection
documentation for further examples - they all work in the same way.The 'category' => solution works for category filtering.
What about when you want to filter by brand and stock level though? We have thousands of products.
Use the
filter
option. https://docs.grabaperch.com/functions/collections/perch-collection/That's for perch collections. How do we move all products or tell perch all my products are a collection?
You use the same principles as described in
perch_collection
. Where it saysperch_collection
, replace that withperch_shop_products
and you're good to go.perch_shop_products
accepts the same options asperch_collection
.Sorry. It doesn't work. Already tried with arrays and this
Here's the debug
This query seems to be doing what you are asking the filter to do - but it's returning nil:
Without knowing your data, it's going to be hard to work out why it's not returning any results. If you only use one filter at a time (say brand first, then try again with just stock_level), are results returned?
Tried changing the query to AND instead of OR. Same results. This
Also returns products with stock_level = 0
See
Drew,
having run this
against a database, I am getting zero results when I would expect one returned row.
It's the
HAVING count(*)=2
that seems to cause the issue - where is the count number generated from?What does
give you?
Yep. That works. Does that need to be default for some reason?