floridaDev Posted September 29, 2016 Share Posted September 29, 2016 I'm having some difficulties returning the sibling pages that have the same field value. <?php #SET VARS $locationData = $page->get("LocationData"); # Get Sibling pages, except current one $sibPages = $page->siblings("id!=$page"); # For each them foreach ($sibPages as $sP) { # Return Sibling pages that share the same "LocationData" field value $sP = $pages->find("LocationData=$locationData"); # Another Loop foreach($sP as $sPP) { echo $sPP->title .'<br />'; } } ?> Page structure Parent Page - Child Page1 (locationData=foo) - Child Page2(locationData=bar) - Child Page3(locationData=foo) - Child Page4(locationData=foo) My desired output would be if I'm on child page 1, to return child page3, and child page4 because they have the same identical field value and are also a sibling page. Instead the output returns me Child page 1, child page 1, child page 3 child page 3, child page 4, child page 4 while being on child page 1. I understand this is happening because of my 2 foreach loop's but I'm not sure how to filter by $page then filter again by $pages. TL;DR My end goal is to return sibling pages with the same field value, except the current page Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 29, 2016 Share Posted September 29, 2016 Something like this ?: $id = $page->id; $pid = $page->parent->id; $locationData = $page->get("LocationData"); $relatedPages = $pages->find("parent=$pid, id!=$id, LocationData=$locationData"); 7 Link to comment Share on other sites More sharing options...
floridaDev Posted September 29, 2016 Author Share Posted September 29, 2016 40 minutes ago, Martijn Geerts said: Something like this ?: $id = $page->id; $pid = $page->parent->id; $locationData = $page->get("LocationData"); $relatedPages = $pages->find("parent=$pid, id!=$id, LocationData=$locationData"); That did it, thanks a lot. I didn't realize you can include parameters like that in the $pages selector. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 29, 2016 Share Posted September 29, 2016 It's processed as a string.... 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