Jump to content

get all unique values from a page-field in all pages …


ngrmm
 Share

Recommended Posts

$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.
 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...