Jump to content

Page Reference field to supply select options on front


jds43
 Share

Recommended Posts

Hello, I'm trying to list the categories, on the front through select options, that have been selected by page reference field (multiple pages PageArray) on the child pages.

Things to Do (would only display three, six, seven, nine in select)
-thing one (-category three, -category nine)
-thing two (-category six, -category seven)


Lodging (would only display one, two, three, four in select)
-lodging one (-category one, -category two)
-lodging two (-category three, -category four)


Dining (would only display five, six, seven, eight in select)
-dining one (-category five, -category six)
-dining two (-category seven, -category eight)

Categories(hidden page)
-category one
-category two
-category there
-category four
-category five
-category six
-category seven
-category eight
-category nine
-category ten

$categories = $pages->find(1129)->children('include=hidden');
foreach($categories->references('category') as $ref) {
    echo $ref->title;
}

This selector isn't working, but it seems 'references' would be helpful. I've never used it before, so I'm not sure how to employ for this.

https://processwire.com/blog/posts/processwire-3.0.107-core-updates/#page-gt-references

Link to comment
Share on other sites

The below assumes that your Page Reference field on the child pages is named "categories".

If you want duplicates or don't care about duplicates:

foreach($page->children() as $child) {
	foreach($child->categories as $category) {
		echo $category->title;
	}
}

If you don't want duplicates:

// Create empty PageArray that will hold the categories
// By default each page can only exist once in a PageArray (hence no duplicates)
$categories = new PageArray();
foreach($page->children() as $child) {
	$categories->add($page->categories);
}
foreach($categories as $category) {
	echo $category->title;
}

 

  • Like 1
  • Thanks 1
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

×
×
  • Create New...