Jonathan Posted April 3, 2015 Share Posted April 3, 2015 Hi PW community, Here's my code: $films = $pages->find("template=film"); foreach($films as $film){ $poster = $film->poster->size(200, 280); $g = $film->genre; echo "..." If I echo $g, I get the page id of each array item (eg. 1159|1245|1291 etc), but if I echo $g->title I get nothing. I'm quite confused as if I echo $poster->url or path or name, that echoes out just fine. Thanks in advance! Link to comment Share on other sites More sharing options...
adrian Posted April 3, 2015 Share Posted April 3, 2015 It looks like genre is a Page field? You need to get the titles for all the selected genres. You can do another foreach like: foreach($film->genre as $g) { echo $g->title; } or you can make use of WireArray::implode() https://processwire.com/talk/topic/5098-new-wirearray-api-additions-on-dev/ Link to comment Share on other sites More sharing options...
Jonathan Posted April 3, 2015 Author Share Posted April 3, 2015 Thanks Adrian, I knew it was a simple fix and had been trying to get implode working but found PHPs manual a bit confusing. Ryan's examples made it much easier to understand. Cheers $gt = $genre->implode(' ', 'title'); Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 3, 2015 Share Posted April 3, 2015 To make this fully clear. The implode function you're using is a ProcessWire specific implementation of the php function. The php version does only work on arrays and the array has to be passed into the function as parameter. What you're using is a method of the WireArray class, which mimics a lot of the array features, but adds lot more to it. That's why the syntax is different and therefore the php docs wouldn't help to much. 3 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