Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Template Name: WhereToBuy Page Template
  5.  *
  6.  * @package WordPress
  7.  * @subpackage Test Website
  8.  */
  9.  
  10. get_header();
  11.  
  12. ?>
  13.  
  14. <h1>WhereToBuy Page</h1>
  15.  
  16. <script async defer src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEYHERE&callback=initMap"></script>
  17.  
  18. add_shortcode( 'themeprefix_multiple_marker', 'themeprefix_multiple_marker' ); // Create shortcode [themeprefix_multiple_marker]
  19. // Output all dealers via a custom loop of the Dealer CPT and show the title and address field in the marker and link that to the Dealer CPT
  20. function themeprefix_multiple_marker() {
  21.         ob_start();
  22.         $args = array(
  23.                 'post_type'      => 'store',
  24.                 'posts_per_page' => -1,
  25.     );
  26.         $the_query = new WP_Query($args);
  27.         echo "<div class='map-container'><div class='wrap'><div class='acf-map'>";
  28.         while ( $the_query->have_posts() ) : $the_query->the_post();
  29.         $location = get_field('location');
  30.         $title = get_the_title(); // Get the title
  31.         if( !empty($location) ) {
  32.         ?>
  33.             <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
  34.                         <h4><a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?></a></h4>
  35.                         <p class="address"><?php echo $location['address']; ?></p>
  36.             </div>
  37.     <?php
  38.         }
  39.         endwhile;
  40.         echo '</div></div></div>';
  41.         wp_reset_postdata();
  42.   return ob_get_clean();
  43. }
  44.  
  45. <?php
  46.  
  47. get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement