Home Forums Backend Issues (wp-admin) Display markers of a GM Map based on the selection of a taxonomy and gm field Reply To: Display markers of a GM Map based on the selection of a taxonomy and gm field

  • Ok i got it working somehow but i have only two follow up questions regarding the initial problem and the new code. The working snippet looks like that:

    <div class="acf-map"><?php
        $terms = get_field('op-contact-tax', 'option');
        $args = array(
          'post_type' => 'locations',
          'posts_per_page' => -1,
    	$the_query = new WP_Query( $args );
    	if( $the_query -> have_posts() ) : while ( $the_query -> have_posts() ) : $the_query->the_post();
            $termstd = get_the_terms($post->ID, 'thelocations');
            $termsingle = array_shift( $termstd );
            foreach($terms as $term):
            	if( $termsingle->term_id == $term ) {
            	$location = get_field( 'location_gmap' );
            	$termdesc = term_description($term, 'thelocations'); ?>
            	<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>" data-col="<?php echo $termdesc; ?>">
                	<h5><?php the_title(); ?></h5>
                	<p class="address"><span><?php echo the_field( 'location_street' ); ?></span><span><?php echo the_field( 'location_postalcode' ); ?></span> <span><?php echo the_field( 'location_city' ); ?></span></p>
                	<?php $locurl = the_field( 'location_url' );
                	if(!empty($locurl)) { ?>
    		    		<a><?php echo $locurl; ?></a>
    		    	<?php } ?>
          	<?php }
        else: ?>
    	endif; ?>

    The questions:
    1) Would it be possible to move the closing div at the end, a bit upwards, between the endforeach and endwhile so that it would be possible to query within the same loop for more informations which don’t go into the google maps map. I mean you have the loop, within the loop you query for the informations of the google maps block and then also query for blocks of addresses underneath the google maps part and then close the loop. Or do i have to create two separate loops (one for google maps one for addresses). cuz if i move the div up right after the endforeach there is no map displayed anymore.

    2) Is it possible to solve the issue in a more elegant way. For me the code looks a bit messy.

    Best regards Ralf