Forum
Filtering multiple regions by multiple fields?
My else
statement brings back what I'm looking for but when I try and filter it by slug, my if
it comes back empty. I've tried about everything I could find in forums, any suggestions?
My template (partial):
<a class="button resource" href="/town-government/meetings/minutes/<perch:content id="slug" type="slug" />">Meetings Minutes</a>
Code in minutes.php (partial)
if (perch_get('slug')) {
// ... detail mode ...
perch_content_custom(array('Main content', 'Meetings'), array(
'page'=>'/town-government/boards-and-committees/*',
'template'=>'meetings/meeting_minutes.html',
'sort' => 'meeting_date',
'sort-order' => 'DESC',
'filter'=>array(
array(
'filter' => 'meeting_date',
'match' => 'lte',
'value' => date('Y-m-d 23:59:59'),
),
array(
'filter'=> 'slug',
'match'=>'eq',
'value'=> perch_get('slug'),
),
)
'each' => function($item) {
if (isset($item['_pageID'])) {
$Content = PerchContent::fetch();
$Page = $Content->get_page_by_id($item['_pageID']);
if ($Page) {
$item['_page_title'] = $Page->pageTitle();
}
}
return $item;
}
));
} else {
// ... list mode ...
perch_content_custom(array('Main content', 'Meetings'), array(
'page'=>'/town-government/boards-and-committees/*',
'template'=>'meetings/meeting_minutes_slug.html',
'sort' => 'meeting_date',
'sort-order' => 'DESC',
'filter' => 'meeting_date',
'match' => 'lte',
'value' => date('Y-m-d 23:59:59'),
'each' => function($item) {
if (isset($item['_pageID'])) {
$Content = PerchContent::fetch();
$Page = $Content->get_page_by_id($item['_pageID']);
if ($Page) {
$item['_page_title'] = $Page->pageTitle();
}
}
return $item;
}
));
}
You're pulling content from multiple regions - are they using the same template?
Drew thank you, your question sparked me to rethink my approach. Turns out that with the added
each
function, I didn't need both regions. Then I ended up grabbing the slug and adding it to the 'page=>' option to eliminate a lot of stuff that was over complicating things.Final code:
Great.