Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using WP_Query to pull out our stores, loop through and output into a list
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'store'
);
$stores = new WP_Query( $args );
?>
<?php if ( $stores->have_posts() ) : ?>
<div id="store-locations-map" style="width: 100%; height: 300px;"></div>
<ul id="stores">
<?php while ( $stores->have_posts() ) : $stores->the_post() ?>
<?php
$phone = get_post_meta( get_the_ID(), '_cmb_phone', true );
$location = get_post_meta( get_the_ID(), '_cmb_location', true );
?>
<li data-latitude="<?php echo $location['latitude']; ?>" data-longitude="<?php echo $location['longitude']; ?>">
<h2><?php the_title(); ?></h2>
<p>Telephone: <?php echo $phone; ?></p>
</li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment