Right now, the values of the city selector are stored in a multi-dimensional array. We understand having the city selector values as single meta values makes it easier to search and query posts.
Storing this as single values, is on our to do list, but we won't promise if it will make its way into the plugin, or any ETA for it.
If you use 1 single city selector field on a post, then we have a 'workaround' for you.
IMPORTANT: This will NOT work if you have multiple instances of the field, like in a repeater/flexible content or group. More than 1 single instance does not work either.
function acfcs_store_single_meta_values( $post_id ) {
$city_selector_field = 'your_field_key'; // example field_61900444dd7e2
if ( isset( $_POST[ 'acf' ][ $city_selector_field ] ) ) {
$city_selector = $_POST[ 'acf' ][ $city_selector_field ];
$country = ( isset( $city_selector[ 'countryCode' ] ) ) ? $city_selector[ 'countryCode' ] : false;
$city = ( isset( $city_selector[ 'cityName' ] ) ) ? esc_html( $city_selector[ 'cityName' ] ) : false;
$state = ( isset( $city_selector[ 'stateCode' ] ) ) ? substr( $city_selector[ 'stateCode' ], 3 ) : false;
if ( false != $post_id ) {
update_post_meta( $post_id, 'meta_key_country', $country );
update_post_meta( $post_id, 'meta_key_state', $state );
update_post_meta( $post_id, 'meta_key_city', $city );
}
}
}
add_action( 'acf/save_post', 'acfcs_store_single_meta_values' );
After that you can use a simple meta query to get the correct posts.
$args = [
'post_type' => 'post',
'meta_query' => [
[
'key' => 'meta_key_city',
'value' => 'A city name',
],
],
];
$posts = get_posts($args);