Jump to content

Grouping PageReference pages but their parent on the front end


a-ok
 Share

Recommended Posts

Apologies if this has been asked before but I'm a little stumped. This also be more of a general-PHP question but was curious if Processwire offered anything to make this more efficient?

I have a PageReference field on a product template and the client can select as many references for the template "products-code-option" as they wish. These are organised in the CMS as products-code-section (parent) then products-code-option (child). See screenshot.

Anyway, my question is I'd like to build an array sorting the pages selected into their parent titles.

$result = array();
foreach ($page->products_codes as $option) {
	$result[$option->parent->name]["title"] = $option->parent->title;
	$result[$option->parent->name][] = $option;
}

bdb($result);

This is what I have so far, which kind of works, but it's not adding the options into a single array but rather their own array for each option (see last screenshot).

Any thoughts where I'm going wrong?

Screenshot 2023-01-06 at 12.07.14@2x.jpg

Screenshot 2023-01-06 at 11.55.56@2x.jpeg

Screenshot 2023-01-06 at 13.54.23@2x.jpg

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