Home Forums General Issues Complicated State/City/Neighboord Selection


Complicated State/City/Neighboord Selection

  • I’m trying to determine if this is possible using this plugin. Essentially I have a post type for a business and that business needs to select from a per-determined list of states, cities, and neighborhoods.

    I’ve already created that array using nested repeater fields on an option page. I’ve created 3 blank select fields that display on each business post called state, city, and neighborhood. I’m using the following code to add the states to the state select field.

    function acf_load_state_field_choices( $field ) {
    	$field['choices'] = array();
    	$states = get_field('states', 'option');
    	if (is_array($states)) {
    		foreach ($states as $state) {
    			$state_name = $state['state_name'];
    			$field['choices'][ $state_name ] = $state_name;
    	return $field;
    add_filter('acf/load_field/name=state', 'acf_load_state_field_choices');

    My question is, is there any way to make it so when I select the state, it automatically clears the city select choices, and populates it with all the cities available for the selected state? And then does the same thing for the neighborhood select when the city is selected?

  • Hi @the-logicor,

    Thanks for the post.

    You can clear the choices in the select field through the code :

    $field['choices'] = array();

    You can then attach some logic to check for the selected value using the get_field() and then call the function.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Complicated State/City/Neighboord Selection’ is closed to new replies.