Skip to content

Instantly share code, notes, and snippets.

@alexadark
Last active July 25, 2017 15:03
Show Gist options
  • Save alexadark/4c9bdf4de2222eaefa914db82119db33 to your computer and use it in GitHub Desktop.
Save alexadark/4c9bdf4de2222eaefa914db82119db33 to your computer and use it in GitHub Desktop.
<?php
//template for restaurants
//query arguments
return array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'wst_long_lat',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
//display code
<?php include( WP_PLUGIN_DIR . '/facetwp-map-template-master/includes/display-code.php' ); ?>
<!--display code file -->
<?php
$locations = array();
while ( have_posts() ) : the_post();
//echo "has_term : ".has_term('restaurants-in-mallorca', 'business-categories', $post->ID);
$terms = get_the_terms( $post->ID, 'business-categories', "", "", "</br>" );
$cat = get_the_terms( $post->ID, 'category', "", "", "</br>" );
//echo "</br> has_category : ".has_category('restaurants', $post->ID)."</br>";
if(has_term('restaurants-in-mallorca', 'business-categories', $post->ID) || has_term(17, 'category', $post->ID)) :
echo "<p class='hidden_post' style='display:none;''>".get_the_title()."</p>";
$distance = facetwp_get_distance( $post->ID );
$distance = ( false !== $distance ) ? '<br />' . round( $distance, 1 ) . ' miles away' : '';
if(get_field('wst_long_lat')) :
$locations[] = array(
'title' => get_the_title( $post->ID ),
'coords' => get_field('wst_long_lat'),
'distance' => $distance,
'permalink' => get_permalink( $post->ID )
);
endif;
endif;
endwhile;
//echo "<h2>Displaying map</h2>";
//print_r($locations);
<?php
$locations = array();
while ( have_posts() ) : the_post();
//echo "has_term : ".has_term('restaurants-in-mallorca', 'business-categories', $post->ID);
$terms = get_the_terms( $post->ID, 'business-categories', "", "", "</br>" );
$cat = get_the_terms( $post->ID, 'category', "", "", "</br>" );
//echo "</br> has_category : ".has_category('restaurants', $post->ID)."</br>";
if(has_term('restaurants-in-mallorca', 'business-categories', $post->ID) || has_term(17, 'category', $post->ID)) :
echo "<p class='hidden_post' style='display:none;''>".get_the_title()."</p>";
$distance = facetwp_get_distance( $post->ID );
$distance = ( false !== $distance ) ? '<br />' . round( $distance, 1 ) . ' miles away' : '';
if(get_field('wst_long_lat')) :
$locations[] = array(
'title' => get_the_title( $post->ID ),
'coords' => get_field('wst_long_lat'),
'distance' => $distance,
'permalink' => get_permalink( $post->ID )
);
endif;
endif;
endwhile;
//echo "<h2>Displaying map</h2>";
//print_r($locations);
?><script>window.map_data = <?php echo json_encode( $locations ); ?>;</script>
//code in the wp page :
<div class="map-facet">[facetwp facet="search_map"]</div>
<div>[facetwp template="map"]</div>
//Template for hotels
//query agruments
<?php
return array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'wst_long_lat',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
//display code
<?php include( WP_PLUGIN_DIR . '/facetwp-map-template-master/includes/display-hotels.php' ); ?>
<!--display hotels file-->
<?php
$locations = array();
while ( have_posts() ) : the_post();
//echo "has_term : ".has_term('restaurants-in-mallorca', 'business-categories', $post->ID);
$terms = get_the_terms( $post->ID, 'business-categories', "", "", "</br>" );
$cat = get_the_terms( $post->ID, 'category', "", "", "</br>" );
//echo "</br> has_category : ".has_category('restaurants', $post->ID)."</br>";
if(has_term('hotels-mallorca', 'business-categories', $post->ID) || has_term(810, 'category', $post->ID)) :
echo "<p class='hidden_post' style='display:none;''>".get_the_title()."</p>";
$distance = facetwp_get_distance( $post->ID );
$distance = ( false !== $distance ) ? '<br />' . round( $distance, 1 ) . ' miles away' : '';
if(get_field('wst_long_lat')) :
$locations[] = array(
'title' => get_the_title( $post->ID ),
'coords' => get_field('wst_long_lat'),
'distance' => $distance,
'permalink' => get_permalink( $post->ID )
);
endif;
endif;
endwhile;
//echo "<h2>Displaying map</h2>";
//print_r($locations);
?><script>window.map_data = <?php echo json_encode( $locations ); ?>;</script>
<!--code in the wp page-->
<div class="map-facet">[facetwp facet="search_map"]</div>
<div>[facetwp template="hotel"]</div>
// i have even try to create a new facet with the same paraneters, but it doesn't work neither
@Mohaesse
Copy link

Hello alexadark,

I have small question for the distance part its not walking for me
$distance = facetwp_get_distance( $post->ID );
$distance = ( false !== $distance ) ? '
' . round( $distance, 1 ) . ' miles away' : ''
Thanks to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment