$label ) { $countries[] = [ 'code' => $country_code, 'name' => esc_attr__( $label, 'acf-city-selector' ), ]; } // get states for these countries if ( ! empty( $countries ) ) { $states = array(); foreach ( $countries as $country ) { $states[] = array( 'state' => 'open_optgroup', 'name' => esc_attr__( acfcs_get_country_name( $country[ 'code' ] ), 'acf-city-selector' ), ); $order = 'ORDER BY state_name ASC'; if ( 'FR' == $country[ 'code' ] ) { $order = "ORDER BY LENGTH(state_name), state_name"; } $sql = $wpdb->prepare( " SELECT * FROM " . $wpdb->prefix . "cities WHERE country_code = %s GROUP BY state_code " . $order, $country[ 'code' ] ); $results = $wpdb->get_results( $sql ); if ( count( $results ) > 0 ) { foreach ( $results as $data ) { $states[] = array( 'state' => strtolower( $data->country_code ) . '-' . strtolower( $data->state_code ), 'name' => esc_attr__( $data->state_name, 'acf-city-selector' ), ); } } $states[] = array( 'state' => 'close_optgroup', 'name' => '', ); } } } // if has searched if ( isset( $_POST[ 'acfcs_search_form' ] ) ) { $search_limit = false; $where = array(); if ( false != $search_criteria_state ) { $where[] = "state_code = '" . substr( $search_criteria_state, 3, 3) . "' AND country_code = '" . substr( $search_criteria_state, 0, 2) . "'"; } elseif ( false != $search_criteria_country ) { $where[] = "country_code = '" . $search_criteria_country . "'"; } if ( false != $searched_term ) { $search[] = 'city_name LIKE "%' . $searched_term . '%"'; if ( $search_criteria_country || $search_criteria_state ) { $where[] = '(' . implode( ' OR ', $search ) . ')'; } else { $where[] = implode( ' OR ', $search ); } } if ( 0 != $selected_limit ) { $search_limit = "LIMIT " . $selected_limit; } if ( ! empty( $where ) ) { $where = "WHERE " . implode( ' AND ', $where ); } else { $where = false; } if ( 'state' == $searched_orderby ) { $orderby = 'ORDER BY state_name ASC, city_name ASC'; } else { $orderby = 'ORDER BY city_name ASC, state_name ASC'; } $sql = "SELECT * FROM " . $wpdb->prefix . "cities " . $where . " " . $orderby . " " . $search_limit . " "; $cities = $wpdb->get_results( $sql ); $city_array = array(); foreach( $cities as $city_object ) { $city_array[] = (array) $city_object; } if ( ! empty( $city_array ) ) { uasort( $city_array, 'acfcs_sort_array_with_quotes' ); } $result_count = count( $city_array ); } // output ?>

ACF City Selector

0 ) { ?>
1 ) { ?>
+
+
+