swampmusic Posted January 27, 2017 Share Posted January 27, 2017 (edited) HI, I have a newbie question, seem to have got myself into a twist trying to get related pages showing home- - destinations - continents - africa - country1 - country2 - country3 - hotels -hotel1 -hotel2 -hotel3 The country template has a title textfield that stores country name eg; France, Italy, etc.... It also has a page select field that retreives all the hotels using this code... so i can show some hotels on the country page. return $pages->find("template=hotel"); The hotel template has a page select field that retreives the countries for africa using... parent=/en/destinations/africa So each hotel has a country stored on its record using the page select field My problem is that in the php for the country template I need to filter the hotels for only hotels in that country... for example.., return $pages->find("template=hotel, hotel.country = this country.name "); the field filter above is psuedo code it's the bit i can't figure out how to work. Any ideas ? Edited January 27, 2017 by swampmusic code blocks Link to comment Share on other sites More sharing options...
kongondo Posted January 27, 2017 Share Posted January 27, 2017 (edited) Untested. Try this: return $pages->find("template=hotel, country=$page"); Here I am assuming that the page field in the hotel template is named 'country'. Edited January 27, 2017 by kongondo Link to comment Share on other sites More sharing options...
swampmusic Posted January 27, 2017 Author Share Posted January 27, 2017 I solved it in the end using this code in the fields Custom PHP Box .... return $pages->find("template=hotel, countriesbydestination=$page->title"); where the $page->title of the country page holds the country name, and the countriesbydestination is on the hotel page and holds the hotels country It seems to work ok. Thanks for your comment, it made me look onto the $page for the fix Link to comment Share on other sites More sharing options...
kongondo Posted January 27, 2017 Share Posted January 27, 2017 Cool. Did my code work though? Probably the titles won't be changing, but if they will, it is more reliable to check by $page. 2 Link to comment Share on other sites More sharing options...
swampmusic Posted January 27, 2017 Author Share Posted January 27, 2017 Not directly, but it pointed me in the right direction. I had some confusing errors - my mistake - on choosing wrong type of select box/drop down on field. Couldn't figure out why the filtering wouldn't work. Eventually went to database and saw dupe records, so then checked and changed Drop downs from multi to single. Only been working on ProcessWire for a week, so very new to it. One thing, when I went to the DB to see what was being saved, I couldn't believe how lean the data model is. Ryan or whoever has really done a brilliant job here. It will be interesting to see how my coming months go as I will be 100% on Processwire, looking forward to the ride 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