Hello everyone
I want to get pages filtered by several blueprint-values.
It works with just one filterBy(). In the kirby guide are examples with more than one,
so this should actually work, but it dos’nt.
The $_REQUEST[‘filter’] works fine and give my the exact blueprint-value.
The code:
<?
$urlCheck = $_SERVER['REQUEST_URI'];
if (count($_REQUEST) > 0 && stripos($urlCheck, 'filter') !== false){
$selection = page('work')
->children()
->filterBy('hashtag_1', '==', $_REQUEST['filter'])
->filterBy('hashtag_2', '==', $_REQUEST['filter'])
->filterBy('hashtag_3', '==', $_REQUEST['filter']);
}
else {
$selection = page('work')->children()->shuffle()->limit(12);
};
?>
The blueprint section:
hashtag_1:
label: Hash 1
type: text
width: 1/3
hashtag_2:
label: Hash 2
type: text
width: 1/3
hashtag_3:
label: Hash 3
type: text
width: 1/3
This filter only works if you have results for all values (“AND” logic). Is that what you want?
Ich hoffe deutsch ist auch ok. Fällt mir einwenig einfacher…
Danke für die rasche Antwort.
$_REQUEST[‘filter’] beinhaltet beispielsweise den value “visualisierung”. Jetzt sollten die Pages raus gefiltert werden, die in einem, oder theoretisch auch mehreren der angegebenen Blueprint-Positionen (hashtag_1, hashtag_2, hashtag_3) den Value “visualisierung” enthalten.
Habe es so gelöst und funktioniert.
<?
$urlCheck = $_SERVER['REQUEST_URI'];
if (count($_REQUEST) > 0 && stripos($urlCheck, 'filter') !== false){
$selection = page('work')->children()->filterBy('hashtag_1', '==', $_REQUEST['filter']);
$selection->add(page('work')->children()->filterBy('hashtag_2', '==', $_REQUEST['filter']));
$selection->add(page('work')->children()->filterBy('hashtag_3', '==', $_REQUEST['filter']));
}
else {
$selection = page('work')->children()->shuffle()->limit(12);
};
?>
Great you found a solution, although there is a better way to achieve this with the filter()
method instead of filterBy()
.
The forum language is English, so it would be great if you could stick to it, otherwise, people from other parts of the world cannot understand you. Thanks for your understanding.