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
getQueryObject
but I don't know how to translate attributes into it.
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

ESKEMA
 
TheRealSean replied on at Permalink Reply
TheRealSean
I've not attempted any of this but you could try `orWhere`

$list->getQueryObject()
    ->where('p.clsActive', 1)
    ->andWhere('p.clsTemplate', 0)
    ->orWhere('p.clsTemplate', 1)
    ->orWhere('p.clsTemplate', 2)
    ->orderBy('p.cDisplayOrder', 'ASC');
ESKEMA replied on at Permalink Reply
ESKEMA
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..
goesredy replied on at Permalink Reply
goesredy
I know its a bit late, but you can use something like this.
$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)");
ESKEMA replied on at Permalink Reply
ESKEMA
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.
DKPatel replied on at Permalink Reply
$list->filterByAttribute($Attribute, $AttributeValue, $comparison);
visit root/concrete/src/Search/ItemList/Database/AttributedItemList.php