Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

ACF City Selector

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 (active) for it to run.


1.10.1 - released 29.12.22


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

Screenshot ACF City Selector

It creates a new field type for you to choose when you're creating an ACF Field Group.


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


  1. Download the latest release zip file.
  2. In your WordPress admin, go to Plugins -> Add New
  3. Click Upload Plugin
  4. Upload the zip file that you just downloaded.
  5. Activate the ACF City Selector plugin via the plugins page.

If you use a composer file to add any plugins/libraries. Add the following to your composer.json:

  "repositories": [
      "type": "composer",
      "url": ""

Then run composer require "wpackagist-plugin/acf-city-selector"


  1. Create a new field via ACF and select the City Selector type (listed in the Choice section).
  2. Select if you want to show labels (default = yes)
  3. Select if you want to use select2 (default = no) [ACF pro only]
  4. Select if you want a default country (default = none)
  5. (optional) Import new cities with help of the included Excel sheet.
  6. (optional) Import new cities by csv (available on the website).


When the field is used by a single field, 3 values are stored in an array:

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

When the field is used in a repeater field, the values are stored in a multidimensional array:

array(2) {
  array(3) {
    string(2) "BE"
    string(5) "BE-BR"
    string(10) "Anderlecht"
  array(3) {
    string(2) "NL"
    string(5) "NL-FL"
    string(6) "Almere"

The reason why the state is prefixed (with the country code) in the database is because there can be states/provinces which use the same abbreviation as in another country. You won't notice this, since this value is formatted on return.

The return value gets overridden, so you get 'more return info' and a 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 comes with all cities in Belgium and the Netherlands 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.

There are a few country packages (csv files) available. These packages can be imported as is. These are available through the ACFCS website.


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

Find all actions here.


Find all filters here.


A few custom functions are available for you to easily retrieve data.

Find all functions and their info here.


This ACF field type is compatible/tested with ACF 5 (Pro). It's slightly tested with the free version (v4), but we won't be putting any (more) time in it. Just buy the Pro version. It's worth every cent !

Tested with

  • Wordpress 6.1.1
  • Advanced Custom Fields Pro 6.0.5
  • Advanced Custom Fields 4.4.12


If you need support, please turn to Github. It's faster than the Wordpress support.



The plugin works in the following situations:

  • in a single field
  • in a repeater field
  • in a group
  • in a flexible content block
  • in an accordion field
  • as a cloned field
  • on taxonomy terms
  • on settings pages

The plugin does NOT work properly yet in the following situations:

  • when multiple instances of the field are used in 1 group/on 1 post

It might have some twitches with taxonomies, but need some more testing.

Sometimes the loading of states/cities, takes a few seconds... Don't know why yet... This seems to be very random and unpredictable.


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

Jarah de Jong helped me out with some JS at the start and John McDonald did some of the German translations.



  • new language files


  • add option to store location as single meta values
  • fix ordering for states (which caused some issues)


  • fixed incorrect version


  • fixed case in states transient
  • added wpdb->prepare (where needed)
  • reverted version by function due to some people reporting errors


  • fixed preview
  • fixed city names with an '
  • fixed city names with special characters


  • fixed raw import


  • removed import of free countries on plugin activate
  • removed country transient due to incorrect names being stored when using multiple languages


  • added new options to v4 version (which were already available for v5)
  • improve adding of ajax url
  • add filter to change user cap to access settings
  • sprintf a lot of values
  • prefix input names to prevent any errors
  • clean up files
  • make more functions to prevent 'spaghetti code'


  • fix broken image in readme
  • change incorrect filter to action
  • simplified some IF statements
  • sprintf more output
  • translated some strings


  • escape attributes in dropdowns (via @hardweb-it)


  • fix styling which was overriding the styling of other messages
  • remove function from uninstall.php which prevented deleting of plugin


  • fix non-showing errors on verify csv file
  • show all errors, instead of just first encountered
  • fix dismiss error button


  • don't pre-load cities on country change
  • fix help tab which overrides other plugins' help tabs
  • stripslash searched value (admin)
  • update default csv (fixed some typos with 's and 't)


  • fix typos + capitalization

1.0.0 - first release in WP repo

  • prefix javascript function names


  • escape js value


  • escape user inputs


  • code refactoring according to (most) Wordpress standards


  • add acfcs_upload_folder filter
  • improve code by making more 'smaller' functions
  • import preset countries from csv instead of php
  • remove some unnecessary hooks


  • fix version number


  • change default delimiter from , tot ;.
  • change import sheet from , tot ;.
  • fixed non-working max lines setting on import
  • added Japan and South Korea country files
  • extended Spain country file


  • messed up release with version numbers


  • added a fix for select2 in repeaters/flexible content blocks
  • added a fix for incorrect escaping which caused incorrect ordering in names starting with a '.
  • added new function as fallback for acfcs_get_country_name()
  • added China, New Zealand, Aruba and Curaçao country files
  • removed flag assets from plugin
  • changed URLs to new website domain


  • added select2 option
  • changed hide labels filter as fallback for select2
  • added new country packages on the website


  • added a new option: "state/province + city" (for when a default country is set)
  • added a transient for cities per state
  • added 3 new filters to override field labels
  • added a new filter to override showing of field labels
  • (re-)added a check for database version to prevent unnecessary table updates

See older changelogs on the website.


An ACF extension to create a new field type, where you can select a city based on country and provence/state.






No packages published