Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function area_by_country( $selected_country ) {
- $get_locations = get_field( 'location_maps', 'options' ); // Get all locations from options
- $get_southarea = get_field( 'location_sa_maps', 'options'); // Get South Africa areas from options
- $get_southcity = get_field( 'south_africa_cities', 'options'); // Get South Africa cities from options
- // Extract only areas from list of South Africa
- foreach( $get_southarea as $southarea ) {
- $southareas[] = $southarea['sa_area'];
- }
- // Convert South Africa areas from array to comma separated list
- $africa_areas = implode( ', ', $southareas);
- // Convert South Africa to same array as other locations
- $south_africa = array(
- 'area' => 'South Africa',
- 'areas' => $africa_areas,
- 'cities' => $get_southcity,
- );
- // Push South Africa to main array of all other countries
- array_push( $get_locations, $south_africa );
- // Simplify array of all countries
- foreach ( $get_locations as $key => $value ) {
- $country_list[$value['area']] = array(
- 'map' => $value['map'],
- 'area' => $value['areas'],
- 'city' => $value['cities']
- );
- }
- // Returns Area and City by Country selected
- if (array_key_exists( $selected_country, $country_list)) {
- $arr_areas = explode( ', ', $country_list[$selected_country]['area'] );
- $arr_cities = explode( ', ', $country_list[$selected_country]['cities'] );
- printaj( $arr_areas );
- printaj( $arr_cities );
- }
- return $arr_areas;
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement