Forum
Filtering a region by combination of AND and OR
I'm just wondering if anyone can help or has found a way to filter perch_content_custom with a combination of AND and OR. I am filtering by 2 values, which works well, but I want to be able to filter items that have the first value and the second value as one option or another.
So basically this... what=$what AND where=$where OR where2=$where
This is the current code I have which doesn't include the second 'where'.
$filters = array();
$what = perch_get('what');
$where = perch_get('where');
if (!empty($what)) {
$filters[] = array(
'filter' => 'what',
'match' => 'eq',
'value' => $what,
);
}
if (!empty($where)) {
$filters[] = array(
'filter' => 'where',
'match' => 'eq',
'value' => $where,
);
}
if (!count($filters)) $filters=false;
perch_content_custom('Business Listings', array(
'template' => 'business_listing.html',
'filter' => $filters,
));
At the moment you can't combine AND and OR, but I'm hopeful that is something we'll be able to add in the future.
I thought this was the case. Any ideas or direction for a work around solution for the time being? Using an SQL statement or anything?
If you turn on debug, you can see the query we're running if you want to modify it and go that route.
Sorry to pester Drew. Do you have a link to someone using a custom SQL statement with Perch. I'm sure I had seen it but can't find it.
It's not really something we offer support for. You can use the DB class from the API for running queries - but what you do with it is up to you.
Thanks Drew. Had a search and a play around with $DB = PerchDB::fetch() but just kept getting the following, so I guess I'll just put in the too hard for me basket.
That looks good. Now you can use it.