Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: WhereToBuy Page Template
- *
- * @package WordPress
- * @subpackage Test Website
- */
- get_header();
- ?>
- <h1>WhereToBuy Page</h1>
- <script async defer src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEYHERE&callback=initMap"></script>
- add_shortcode( 'themeprefix_multiple_marker', 'themeprefix_multiple_marker' ); // Create shortcode [themeprefix_multiple_marker]
- // 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
- function themeprefix_multiple_marker() {
- ob_start();
- $args = array(
- 'post_type' => 'store',
- 'posts_per_page' => -1,
- );
- $the_query = new WP_Query($args);
- echo "<div class='map-container'><div class='wrap'><div class='acf-map'>";
- while ( $the_query->have_posts() ) : $the_query->the_post();
- $location = get_field('location');
- $title = get_the_title(); // Get the title
- if( !empty($location) ) {
- ?>
- <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
- <h4><a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_title(); ?></a></h4>
- <p class="address"><?php echo $location['address']; ?></p>
- </div>
- <?php
- }
- endwhile;
- echo '</div></div></div>';
- wp_reset_postdata();
- return ob_get_clean();
- }
- <?php
- get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement