Home › Forums › Front-end Issues › Display google map markers from custom posts on one map › Reply To: Display google map markers from custom posts on one map
You will need to adapt the following to match your fields etc:
<?php
$args = array(
'post_type' => 'stockist',
'order' => 'ASC',
'order_by' => 'title',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
$the_id = get_the_ID();
$location = get_field( 'company_address' );
$link = get_field( 'company_link' );
$phone = get_field( 'company_phone' );
$country = get_field( 'country_name' );
$logo = get_field( 'company_logo' );
$size = 'productsml';
if ( ! empty( $location ) ) {
?>
<div class="acf-map">
<div class="marker text-center" data-lat="<?php echo esc_attr( $location['lat'] ); ?>" data-lng="<?php echo esc_attr( $location['lng'] ); ?>">
<?php
if ( $logo ) {
echo wp_get_attachment_image( $logo, $size );
}
?>
<h3><?php the_title(); ?></h3>
<?php
if ( $location ) {
$address = '';
foreach ( array( 'street_number', 'street_name', 'city', 'state', 'post_code', 'country' ) as $i => $k ) {
if ( isset( $location[ $k ] ) ) {
$address .= sprintf( '<span class="segment-%s">%s<br /></span>, ', $k, $location[ $k ] );
}
}
$address = trim( $address, ', ' );
?>
<p><?php echo esc_html( $location['address'] ); ?></p>
<?php
}
?>
<?php if ( $phone ) { ?>
<p><?php echo esc_attr( $phone ); ?> </p>
<?php } ?>
<?php if ( $link ) { ?>
<a class="button" href="<?php echo esc_url( $link ); ?>">Visit Website </a>
<?php } ?>
</div>
<?php
}
endwhile;
endif;
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.