Skip to content

Instantly share code, notes, and snippets.

@kristarella
Last active July 8, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kristarella/677a5b845575a62e26db to your computer and use it in GitHub Desktop.
Save kristarella/677a5b845575a62e26db to your computer and use it in GitHub Desktop.
Code required for WP Ultimate Search radius search: results-page is the contents of the WordPress page, search.js needs to be included somewhere on the page, and the results template goes in your theme.
Choose "location" from the search bar below and type your location in order to find Bushcare sites near you.
The default distance is 15km, but you can specify your own.
<div id="map-results" class="acf-map"></div>
[wp-ultimate-search-bar]
[wp-ultimate-search-results]
var map;
var bounds;
jQuery(function() {
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
}
map = new google.maps.Map(document.getElementById('map-results'), mapOptions);
bounds = new google.maps.LatLngBounds();
}
google.maps.event.addDomListener(window, 'load', initialize);
});
<?php
/*
* Results template for WP Ultimate Search plugin
*
*/
?>
<?php if ( $wpus_results->have_posts() ) : ?>
<?php while ( $wpus_results->have_posts() ) : $wpus_results->the_post();
printf( '<article %s>', genesis_attr( 'entry' ) );
do_action( 'genesis_entry_header' );
do_action( 'genesis_before_entry_content' );
printf( '<div %s>', genesis_attr( 'entry-content' ) );
do_action( 'genesis_entry_content' );
echo '</div>'; //* end .entry-content
do_action( 'genesis_after_entry_content' );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
do_action( 'genesis_entry_footer' );
echo '</article>';
if ($loc = get_field('lat_lng')) {
?>
<script type="text/javascript">
var latlng = new google.maps.LatLng(<?php echo $loc['lat']; ?>, <?php echo $loc['lng']; ?>);
var marker = new google.maps.Marker({
position: latlng,
title:"<?php echo $loc['address']; ?>"
});
marker.setMap(map);
bounds.extend(latlng);
</script>
<?php }
endwhile; ?>
<script type="text/javascript">
map.fitBounds(bounds);
map.panToBounds(bounds);
</script>
<?php if(wpus_option('clear_search')) { ?>
<a id="wpus-clear-search" class="<?php echo wpus_option('clear_search_class') ?>" href="#"><?php echo wpus_option('clear_search_text'); ?></a>
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<div class="wpus-no-results"><?php echo wpus_option('no_results_msg'); ?></div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment