Page List filter by multiple attributes OR, not AND
Permalink 1 user found helpful
I'm trying to filter a Page List object by multiple attributes but I need them to be inclusive instead of exclusive. So for example if I have 3 select attributes:
Fruits:
— orange
— apple
— banana
Furniture:
— chair
— table
Languages:
— English
— Portuguese
— Spanish
— French
— German
and let's say the attributes I want to filter are:
— apple
— chair
— Portuguese
I want to get ALL the pages that have any of those attributes, not all of them combined.
After some digging, I think I need to use but I don't know how to translate attributes into it.
Here's a sample code I took from the documentation:
Anyone knows how to do this? I don't need to use getQueryObject if there's a better way.
Thanks
Fruits:
— orange
— apple
— banana
Furniture:
— chair
— table
Languages:
— English
— Portuguese
— Spanish
— French
— German
and let's say the attributes I want to filter are:
— apple
— chair
— Portuguese
I want to get ALL the pages that have any of those attributes, not all of them combined.
After some digging, I think I need to use
getQueryObject
Here's a sample code I took from the documentation:
$list->getQueryObject() ->where('p.clsActive', 1) ->or('p.clsTemplate', 0) ->or('p.cDisplayOrder', 'ASC');
Anyone knows how to do this? I don't need to use getQueryObject if there's a better way.
Thanks
I've not attempted any of this but you could try `orWhere`
Hi Sean,
Thanks for the reply, but what would the code for a custom select attribute be using getQueryObject? I don't really know how to put it in that context..
Thanks for the reply, but what would the code for a custom select attribute be using getQueryObject? I don't really know how to put it in that context..
I know its a bit late, but you can use something like this.
Then may your code will looks like:
$list->getQueryObject()->andWhere("(ak_attribute_handle = 'attribute_request' OR ak_attribute_handle is null)");
Then may your code will looks like:
$list->getQueryObject()->andWhere("(ak_fruits_handle = 'apple' OR ak_attribute_handle is null)"); $list->getQueryObject()->andWhere("(ak_furniture_handle = 'chair' OR ak_attribute_handle is null)"); $list->getQueryObject()->andWhere("(ak_languages_handle = 'portuguese' OR ak_attribute_handle is null)");
Hi goesredy,
Thanks for the answer, it may be late for that project but may come in handy in the future or help others.
I’ll try it out when I have some spare time.
Thanks for the answer, it may be late for that project but may come in handy in the future or help others.
I’ll try it out when I have some spare time.
$list->filterByAttribute($Attribute, $AttributeValue, $comparison);
visit root/concrete/src/Search/ItemList/Database/AttributedItemList.php
visit root/concrete/src/Search/ItemList/Database/AttributedItemList.php