Hello, I am trying to build a filter based on the cookbook’s Using filters with forms (e.g. select fields). I fetch all images of a page, every image can have multiple tags. It works if the image has only 1 tag, lets say “White”. I select “White” and it dispays the image. But if it has multiple tags like "White and “Black” and I select “White” it displays nothing. How can I get it working? Thanks a lot in advance!
Blueprint
one:
label: One
type: tags
index: all
Controller
return function($site, $pages, $page) {
$one = $page->images()->pluck('one', ',', true);
$keys = array('one');
$projects = $page->images();
if(r::is('POST') && $data = get()) {
$projects = $page->images()->filter(function($child) use($keys, $data) {
foreach($data as $key => $value) {
if($value && in_array($key, $keys)) {
if(!$match = $child->$key() == $value) {
return false;
}
}
}
return $child;
});
}
return compact('projects', 'one', 'data');
};
Select Form
<form id="filters" method="post">
<select name="one" onchange="this.form.submit()">
<option selected value="">One</option>
<?php foreach($one as $item): ?>
<?php if ($item == "") continue; ?>
<option<?php e(isset($data['one']) && $data['one'] == $item, ' selected') ?> value="<?= $item ?>"><?= $item ?></option>
<?php endforeach ?>
</select>
</form>
Template
$items = $projects;
if($items->count()): ?>
<?php foreach ($items as $item): ?>
<img src="<?= $item->thumb('default')->url() ?>">
<?php endforeach; ?>
<?php endif ?>