Jump to content

[Solved] Select, Page Type, Relations, Custom PHP


Recommended Posts


I have a newbie question, seem to have got myself into a twist trying to get related pages showing :-)


  - destinations

     - continents

         - africa

               - country1

               - country2

               - country3

 - hotels





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...



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 by swampmusic
code blocks
Link to comment
Share on other sites

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

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 :-)


  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...