Arctic Posted December 12, 2019 Posted December 12, 2019 Hello! I suspect I'm overlooking something simple, but I'm trying to loop through several page reference fields at once. However, this only returns results from related_1. $tags = $page->getFields('name=related_1|related_2|related_3'); foreach($tags as $tag) { echo "<a href='$tag->url'>$tag->title</a>"; }
horst Posted December 12, 2019 Posted December 12, 2019 There is no argument to the method page::getFields() https://processwire.com/api/ref/page/get-fields/ https://github.com/processwire/processwire/blob/3bf29d050b7f542f04628fc69c2448466e167acd/wire/core/Page.php#L1274-L1299
3fingers Posted December 12, 2019 Posted December 12, 2019 $pagefields = $page->getFields(); if(wireInstanceOf($pagefields, FieldtypePage)) { foreach($pagefields as $pf) { echo "<a href='$pf->url'>$pf->title</a>"; } } Not tested, it might work though.
Arctic Posted December 12, 2019 Author Posted December 12, 2019 Thanks, that helped! Here's what worked in the end. $allFields = $page->getFields(); foreach ($allFields as $related){ if (strpos($related, 'related') === 0) { //get just the fields that start with related foreach ($related as $tag){ echo "<a href='$tag->url'>$tag->title</a>"; } } } 2
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