I'm building a site that has a directory listing and I want to allow the user to browse by location. The ideal scenario would be that they would follow this sort of a path:

  • go to site.com/browse and select a country
  • this loads site.com/browse/category/uk, then select a region
  • this loads site.com/browse/category/uk/northern-ireland, then select a county
  • this loads site.com/browse/category/uk/northern-ireland/antrim, then select a town/city/area
  • this loads site.com/browse/category/uk/northern-ireland/antrim/belfast

Now, I think I can do this using EE categories. I could even load up the sub categories over ajax each time they select a parent category.

The category structure in EE for locations would look something like this:

  • Country
    • Region/State
      • County
        • Town/City/Area

My issue is that even with 1 country, there would be a lot of categories. I can handle this neatly on the frontend using GWcode Categories I think. But what about the EE CP. If I click to edit an entry, it would need to load up all these categories in a list. That's a lot. What about when we decide to add another country and need loads more categories again. I want to build this right from the start and don't want to have to re-engineer it later. Another problem is trying to import all those categories. There doesn't seem to be a way to do it. I know there are addons like WB Category Select and JP Category Select, but they still don't solve the issue of having 1000s of categories.

This leads me to believe that I should put all the locations into their own channel and use Playa or a relationship field as a way to display them and allow the user to choose them. But if I do this, is there a way in the channel entry page to allow the user to select the first level (country), which would then populate the second level, and so on? Maybe we need to make our own field type or is there something out there I just haven't found yet.

Then, if this is possible, I would need to filter the entries based on their relationship field. I suppose I'd need to use a mix of freebie to get the filter from the url and use playa to filter based on this.

I suppose I'm asking if I'm over complicating this whole thing or is there an easier way of doing this? Any advice or suggestions would be greatly appreciated.

Thanks, Dave

  • 1
    Personally I would recommend something like devot-ee.com/add-ons/google-maps from ObjectiveHTML or a combination of add-ons GeoTagger & GeoFinder ( devot-ee.com/add-ons/geotagger & devot-ee.com/add-ons/geofinder ) to create the location based search as you don't need to maintain the location data Commented Mar 23, 2013 at 16:49
  • I'm working on an addons that fills this needs. Feel free to send me an email to talk about it. [email protected] Commented Mar 23, 2013 at 18:09
  • Just FYI, you don't need GeoTagger or GeoFinder with Google Maps for ExpressionEngine, which can do everything those add-ons can do plus more. Other than that, I agree, you need to geocode your entries so that you could do a proximity search. Commented Mar 24, 2013 at 3:16
  • I am using Google Maps for EE to do a proximity search based on the users current location. One of the searches uses HTML5 geolocation to retrieve the users current lng/lat and submits it to Justin's addon. I'm considering using it more to use the location data of the city in question to do the search. Justin, I may be in touch by email with a few questions if that's ok?
    – davidbehan
    Commented Mar 24, 2013 at 16:29

1 Answer 1


Personally, I think using categories would be a nightmare. Especially when you consider how frequently, this type of data is updated.

I'm not certain where you are getting your data from, but the best option is to store it in new data table within your EE install, and query it.

We haven't had to do lots of countries, but we had to do a State -> County -> City -> Zip Codes set-up for a service directory for a client, before. We downloaded a US Zip Codes database with Counties to use. It's updated annually, I believe. But I'd look at MaxMind products for your situation. The have a free World Cities database. It's stored as common separated text, and can be uploaded to a MySQL table.

We then use a combination of url segments, PHP in template, and EE Queries to produce the drill down. Our's is really all about the 'counties', but you could adapt for 'countries'.

Here's some sample code:

<?php $county=''; ?>

{exp:query sql="
    SELECT DISTINCT county, city, state 
    FROM counties
    WHERE state='{segment_3}' 
        ORDER BY county ASC, city ASC;

<?php if ($county != '{county}') 
   echo '<h5>{county} County  <span align="right"><small>(<a href="{domain}/location/county/{county}/" title="View all of {county} County">view county</a>)</small></span></h5>'; ?>  

       <a href="{domain}/location/{state}/{city}/" title="{city}">{city}</a>, 

<?php $county='{county}'; ?>


That template, then leads to a listing of cities in the county, and people select a city to display services. I'd provide the sample code for that, except, it's more complicated, because our services by city are then broken down by category. So we had to related the city listing to the categories database, to create, so it's more code than you need.

We have both a list and a map implementation, which was fairly easy to do, you just need to make sure every record contains the fields you need. For us, that meant adding 'county' to the normal address field, so our addresses, were

{city}, {state} {zip code}

Your's would need to include region, and country. We go back and update the client's zip_codes with counties database once a year. The segment searches are very quick, because the extra table is indexed, and the query module will allow you to access any tabled stored in the database used for EE.

  • That's great. It's given me a lot to think about and an angle I hadn't considered possible. My question around this is how do you associate the entry with a particular city, state, county, zip code within EE control panel? Are you creating standard input fieldtypes or linking them to this new table somehow? Or, are you using the geolocation of the entry to match against the geolocation of the city/state/zip code/county and doing a proximity search?
    – davidbehan
    Commented Mar 24, 2013 at 16:41
  • Standard EE entry fields. You can use geolocation if you like. Basically, for us, each service (record) already required an address. We added the extra {county} field to the list. Since the service records, pre-existed, we updated the existing records with county data, via city, state, zipcode, then doing a MySQL UPDATE. County is a pulldown menu. I believe we're using Query Field: devot-ee.com/add-ons/query-field. But otherwise it's just a relational query, display records from table A, that match table B based on this criteria. Commented Mar 24, 2013 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.