diff --git a/classes/simplemap.php b/classes/simplemap.php index de3edb5..5fbe14e 100644 --- a/classes/simplemap.php +++ b/classes/simplemap.php @@ -224,7 +224,7 @@ function location_search_form( $atts ) { $city_value = isset( $_REQUEST['location_search_city'] ) ? $_REQUEST['location_search_city'] : ''; $state_value = isset( $_REQUEST['location_search_state'] ) ? $_REQUEST['location_search_state'] : ''; $zip_value = get_query_var( 'location_search_zip' ); - $country_value = get_query_var( 'location_search_country' ); + $country_value = isset( $_REQUEST['location_search_country'] ) ? $_REQUEST['location_search_country'] : $options['default_country']; $radius_value = isset( $_REQUEST['location_search_distance'] ) ? $_REQUEST['location_search_distance'] : $radius; $limit_value = isset( $_REQUEST['location_search_limit'] ) ? $_REQUEST['location_search_limit'] : $limit; $is_sm_search = isset( $_REQUEST['location_is_search_results'] ) ? 1 : 0; @@ -246,10 +246,7 @@ function location_search_form( $atts ) { 'label' => apply_filters( 'sm-search-label-zip', __( 'Zip: ', 'simplemap' ), $post ), 'input' => '', ); - $ffi['country'] = array( - 'label' => apply_filters( 'sm-search-label-country', __( 'Country: ', 'simplemap' ), $post ), - 'input' => '', - ); + $ffi['country'] = $this->add_country_field( $country_value ); $ffi['empty'] = array( 'label' => '', 'input' => '', ); $ffi['submit'] = array( 'label' => '', @@ -520,6 +517,28 @@ function add_distance_field( $radius_value, $units ) { } + /** + * Adds Country field to form. + * + * @param $country_value + * + * @return array + */ + function add_country_field( $country_value ) { + global $post; + + $country_input = ''; + + return array( + 'label' => apply_filters( 'sm-search-label-country', __( 'Country: ', 'simplemap' ), $post ), + 'input' => $country_input, + ); + } + /** * Adds taxonomy fields to search form. * @@ -1124,7 +1143,7 @@ function searchLocationsNear(searchData) { } ?> - var searchUrl = siteurl + '/?sm-xml-search=1&lat=' + searchData.center.lat() + '&lng=' + searchData.center.lng() + '&radius=' + searchData.radius + '&namequery=' + searchData.homeAddress + '&query_type=' + searchData.query_type + '&limit=' + searchData.limit + '&address=' + searchData.address + '&city=' + searchData.city + '&state=' + searchData.state + '&zip=' + searchData.zip + '&pid='; + var searchUrl = siteurl + '/?sm-xml-search=1&lat=' + searchData.center.lat() + '&lng=' + searchData.center.lng() + '&radius=' + searchData.radius + '&namequery=' + searchData.homeAddress + '&query_type=' + searchData.query_type + '&limit=' + searchData.limit + '&address=' + searchData.address + '&city=' + searchData.city + '&state=' + searchData.state + '&zip=' + searchData.zip + '&country=' + searchData.country + '&pid='; // Display Updating Message and hide search results @@ -2237,6 +2256,34 @@ function get_language_options() { return apply_filters( 'sm-language-list', $language_list ); } + /** + * Get the search countries. + * + * Returns the countries that have been populated. + * @return array + */ + function get_search_countries() { + $countries = array(); + $all_countries = $this->get_country_options(); + $args = array( + 'post_type' => 'sm-location', + 'post_status' => 'publish', + 'posts_per_page' => '-1', + ); + $locations = get_posts( $args ); + + foreach ( $locations as $key => $location ) { + $country_code = get_post_meta( $location->ID, 'location_country', true ); + if ( ! isset( $countries[ $country_code ] ) ) { + $countries[ $country_code ] = $all_countries[ $country_code ]; + } + } + + asort($countries); + + return $countries; + } + /** * Get auto locate options. * @@ -2364,6 +2411,7 @@ function register_query_vars( $vars ) { $vars[] = 'location_search_city'; $vars[] = 'location_search_state'; $vars[] = 'location_search_zip'; + $vars[] = 'location_search_country'; $vars[] = 'location_search_distance'; $vars[] = 'location_search_limit'; $vars[] = 'location_is_search_results'; @@ -2529,7 +2577,7 @@ function get_default_shortcode_atts() { 'search_title' => __( 'Find Locations Near:', 'simplemap' ), 'search_form_type' => 'table', 'search_form_cols' => 3, - 'search_fields' => 'labelbr_street||labelbr_city||labelbr_state||labelbr_zip||empty||empty||labeltd_distance||empty' . implode( '', $tax_search_fields ) . '||submit||empty||empty', + 'search_fields' => 'labelbr_street||labelbr_city||labelbr_state||labelbr_zip||labelbr_country||empty||empty||labeltd_distance||empty' . implode( '', $tax_search_fields ) . '||submit||empty||empty', 'taxonomy_field_type' => 'checkboxes', 'hide_search' => '', 'hide_map' => 0, diff --git a/classes/widgets.php b/classes/widgets.php index ae53deb..72668b6 100644 --- a/classes/widgets.php +++ b/classes/widgets.php @@ -57,6 +57,7 @@ public function widget( $args, $instance ) { $show_city = $instance['show_city']; $show_state = $instance['show_state']; $show_zip = $instance['show_zip']; + $show_country = $instance['show_country']; $show_distance = $instance['show_distance']; $default_lat = $instance['default_lat']; @@ -85,6 +86,7 @@ public function widget( $args, $instance ) { $city_value = isset( $_REQUEST['location_search_city'] ) ? $_REQUEST['location_search_city'] : ''; $state_value = isset( $_REQUEST['location_search_state'] ) ? $_REQUEST['location_search_state'] : ''; $zip_value = isset( $_REQUEST['location_search_zip'] ) ? $_REQUEST['location_search_zip'] : ''; + $country_value = isset( $_REQUEST['location_search_country'] ) ? $_REQUEST['location_search_country'] : $options['default_country']; $radius_value = isset( $_REQUEST['location_search_distance'] ) ? $_REQUEST['location_search_distance'] : $options['default_radius']; $limit_value = isset( $_REQUEST['location_search_limit'] ) ? $_REQUEST['location_search_limit'] : $options['results_limit']; @@ -115,6 +117,15 @@ public function widget( $args, $instance ) { if ( $show_zip ) { $location_search .= '