ngrmm Posted November 2, 2017 Posted November 2, 2017 $p are all the pages all $p have a page-reference-field $cat first i exclude all the pages in $p which has no value for $category (multi-field) $p = $pages->find("template='xy', category!=''"); now i want to get an array of all values stored in the $category-Field of these pages.
ngrmm Posted November 2, 2017 Author Posted November 2, 2017 this works $uniques = new \ProcessWire\PageArray(); foreach($p as $item) { $uniques->import($item->category); } 2
Robin S Posted November 2, 2017 Posted November 2, 2017 21 minutes ago, psy said: Instead of looping through a foreach, it may be quicker to use: $p = $pages->find("template='xy', category!=''"); $uniques = $p->unique(); // or even less code with: $p = $pages->find("template='xy', category!=''")->unique(); This isn't quite the same thing. What @ngrmm wants is unique categories (stored within a Page Reference field on each 'xy' page). Also, it is never necessary to do $pages->find($selector)->unique() because a PageArray is automatically unique.
psy Posted November 2, 2017 Posted November 2, 2017 Thanks @Robin S. too early in the morning. Realised I'd misread the requirement and edited my post.
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