a-ok Posted January 6, 2023 Share Posted January 6, 2023 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? Link to comment Share on other sites More sharing options...
gebeer Posted January 7, 2023 Share Posted January 7, 2023 Have you tried $page->products_codes->sort("parent.title")? Link to comment Share on other sites More sharing options...
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