An ACF extension to create a new field type, where you can select a city based on country and provence/state.
Branch: master
Clone or download
Latest commit eeaf3e1 May 26, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets Change css to field_type Oct 5, 2017
fields Move globa wpdb into IF Nov 4, 2017
import Update import sheet with 3 examples Oct 1, 2017
lang i18n Oct 5, 2017
lib Change 's- to 's[space] Nov 4, 2017
.gitignore Remove something :) Nov 2, 2017
ACF_City_Selector.php Change ENV May 26, 2018 Forgotten version update Feb 12, 2018
composer.json Composer file Sep 22, 2017
readme.txt Readme Feb 10, 2018
uninstall.php Refactor Oct 5, 2017

ACF City Selector Field

Welcome to the City Selector plugin, which is an extension for Advanced Custom Fields. This is not a stand-alone plugin, you'll need ACF for it.




  1. Copy the acf-city-selector folder into your wp-content/plugins folder.
  2. Activate the ACF City Selector plugin via the plugins admin page.
  3. Create a new field via ACF and select the City Selector type (listed in the Choice section).
  4. (optional) Import new cities with help of the included excel sheet.
  5. Please refer to the description for more info regarding the field type settings.


This plugin allows you to select a city, based on country and province/state in an ACF Field Group.

Screenshot ACF City Selector

It creates a new 'field type' for you to choose when you're creating an ACF Field Group. If you click '+ add field' in a Field Group, you will find a new option (category: "Choice") to choose called City Selector.

  • Add the field.
  • Choose any name you want.
  • Choose any key you want.
  • Select whether to show labels above the input fields (default = yes)
  • Save/publish the Field Group.


3 values are stored in an array:

array(3) {
  string(2) "NL"
  string(5) "NL-NH"
  string(9) "Amsterdam"

The reason why the country is prefixed in the storage is because there can be states/provinces which use the same abbreviation. You won't notice this, since we format this value on return.

We override the return value so you get more return info and properly formatted (stateCode). 5 values are returned:

array(5) {
  string(2) "NL"
  string(5) "NH"
  string(9) "Amsterdam"
  string(13) "Noord-Holland"
  string(11) "Netherlands"

Echo it as follows:

$city_selector = get_field('field_name');
echo 'I live in ' . $city_selector['cityName'];
echo 'which is in ' . city_selector['stateName'] . ' (' . city_selector['stateCode'] . ')'; 
echo ' which lies in the country: ' . $city_selector['country'] . ' (' . $city_selector['countryCode'] . ')';

This outputs:

"I live in Amsterdam which is in the state Noord-Holland (NH) which lies in the country Netherlands (NL)".


The plugin adds a database table named {$wpdb->prefix}cities upon plugin activation and imports cities from 3 different countries.


The plugin comes with all cities in the Benelux (Belgium, Netherlands, Luxembourg) pre-installed.

You can also add more countries yourself, through SQL or CSV import. There's a simple excel sheet included in the plugin and can be found in the import folder. With this sheet, you can easily create an SQL insert statement or a CSV data set.

The explanation on how to do this, can be found on the first tab/sheet of the excel file.

We have created several country packages (csv files) especially for this plugin. These files are ready to go and can be imported without right away. These will be made available for a small fee soon, through the ACFCS website.


There are a few hooks available to add your own custom actions.

  • acfcs_after_success_verify - hooks after successful csv verification
  • acfcs_after_success_import - hooks after successful csv import
  • acfcs_after_success_import_raw - hooks after successful raw csv import
  • acfcs_after_success_import_be - hooks after importing preset country Belgium
  • acfcs_after_success_import_lu - hooks after importing preset country Luxembourg
  • acfcs_after_success_import_nl - hooks after importing preset country Netherlands
  • acfcs_after_success_nuke - hooks after truncating the table


This ACF field type is compatible/tested with ACF 4 (Free) as well as ACF 5 (Pro).


The plugin contains the following languages:

  • php
  • javascript / jquery
  • sql
  • css

Tested on

  • Wordpress 4.9.4
  • Advanced Custom Fields 4.4.12
  • Advanced Custom Fields Pro 5.6.8

To Do

  • - Test on Mac Firefox
  • - Test on Mac Safari
  • - Test on PC Chrome
  • - Test on PC Firefox
  • - Test on PC Safari
  • - Test on iPhone Chrome
  • - Test on iPhone Safari
  • - Test on iPad Chrome
  • - Test on iPad Safari


If you need support, please turn to Github.

Remove donation notice

If you want to remove the donation box in ACF, add the following line to functions.php: add_filter('remove_acfcs_donate_nag', '__return_true');

Website (not for support)


This plugin is not 100% finished yet. It most likely won't break anything but use caution, just in case.


I got the idea for this plugin through Fabrizio Sabato who used it a bit differently, which can ben seen here.

Since I couldn't fix the Javascript for this plugin, Jarah de Jong took care of it.


0.3 Added hooks for import/delete actions

0.2 Added database collation