baronmunchowsen Posted April 1, 2020 Share Posted April 1, 2020 I have a repeater matrix that is used on multiple pages. The repeater matrix contains the following repeater matrix types: quote, hero, text, ... 'quote' is made up of 3 fields: quote_text, quote_source, quote_link I would like to return all instances of the matrix repeater type 'quote' used on any pages. Ideally I would have an array of objects that I could then access the 3 quote fields from. Is this possible within the processwire field/page api? Many thanks for any insights. Link to comment Share on other sites More sharing options...
kixe Posted April 1, 2020 Share Posted April 1, 2020 Example with a multidimensional array. RepeaterMatrix fieldname = 'fieldname' first level: page where the repeater field lives in, indexed by ID second level: per page repeater items indexed by ID third level: field inside repeater indexed by name $rp = $pages->find('fieldname.count>0'); $return = []; foreach ($rp as $p) { $return[$p->id] = []; // RepeaterMatrixPageArray foreach ($p->fieldname as $item) { if ($item->type != 'basic') continue; $return[$p->id][$item->id] = []; // RepeaterMatrixPage foreach ($item->template->fields as $repeaterField) { if ($repeaterField == 'repeater_matrix_type') continue; // we do not need this if ($item->$repeaterField === '') continue; // if you want to ignore empty strings $return[$p->id][$item->id]["$repeaterField"] = $item->$repeaterField; } // remove if empty if (empty($return[$p->id][$item->id])) unset($return[$p->id][$item->id]); } // remove if empty if (empty($return[$p->id])) unset($return[$p->id]); } var_dump($return); 1 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