2

I have a collection/channel of products, where each product belongs to multiple categories. I have two category groups: product and collection. Example product categories include 'shirts' and 'hats'. Example collection categories include 'blue' and 'on sale'. collection categories can be thought of as children of product categories, though in the EE backend, their category groups are siblings.

I have a form that lets you input a keyword to search by, and then a tree of the product and collection categories.

I have a pseudo-query of what I need to accomplish:

SELECT
  products
WHERE
  keyword = 'foo'
AND 
(
  ( product_cat = 'shirt' AND ( collection_cat = 'blue' OR collection_cat = 'on sale' ) )
  OR 
  ( product_cat = 'hat' AND ( collection_cat = 'blue' ) )
)

I know you can search through multiple categories by sending an array of category IDs, but in this case I need to have a parent-child category relationship.

Is this possible?

1

That specific example isn't possible, but you can get pretty close, despite not being able to account for the quasi-relationship between category groups you've defined.

With Low Search, you can do the equivalent of this:

SELECT * FROM entries
WHERE keyword = 'foo'
AND (product_cat = 'shirt' OR product_cat = 'hat')
AND (collection_cat = 'blue' OR collection_cat = 'on sale')

..which is the same as:

SELECT * FROM entries
WHERE keyword = 'foo'
AND product_cat IN ('shirt', 'hat')
AND collection_cat IN ('blue', 'on sale')

...thus also searching for hats on sale.

| improve this answer | |
  • Thanks for your reply, I was afraid it wouldn't be possible. I'm currently using category group filtering, but it'd be great if we had tighter control over the filtering. Something like setting the input name to category:foo:and[] or category:bar:or[] would be great :) – Arms Feb 26 '13 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.