ngrmm Posted August 9, 2016 Posted August 9, 2016 i have a filter and use buttons for filtering. i want to get all selected values from a page-field (multi) in different pages (same parent). sorted by title (title of the pages) <div class="controls" id="Filters"> <h3>Size</h3> <button class="filter" data-filter=".size_page-title-1">38</button> <button class="filter" data-filter=".size_page-title-2">40</button> <button class="filter" data-filter=".size_page-title-3">42</button> <button class="filter" data-filter=".size_page-title-4">44</button> <button class="filter" data-filter=".size">all</button> </div>
ngrmm Posted August 9, 2016 Author Posted August 9, 2016 that's my solution but where can i sort the array by title? <?php $children = $page->children; $uniques = array(); foreach ($children as $child) { $sizes = $child->size; $s = $sizes; foreach($s as $g) { $uniques[$g->id] = $g->title; } } foreach ($uniques as $id => $title) { echo "<button class='filter' data-filter='.size_$title'>$title</button>"; } ?>
Robin S Posted August 9, 2016 Posted August 9, 2016 Better to store the selected pages in a PageArray: $children = $page->children; $uniques = new \ProcessWire\PageArray(); // assumes PW3 foreach($children as $child) { $uniques->import($child->size); } $uniques->sort("title"); foreach($uniques as $unique) { echo "<button class='filter' data-filter='.size_{$unique->title}'>{$unique->title}</button>"; } 3
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now