Foreach loop inside foreach loop?

Your 2nd foreach loop is a bug. $slug is a string with a single value, and you cannot pass a string to a foreach loop. If you set debug to true, you will see an error message telling you just this. You can simply just do //Different markers for different types $car_type = get_the_terms( $post->ID, … Read more

Implement Google Maps JS on WordPress

First of all enqueue the Google Maps API js in the right way. look for a function which is hooked on wp_enqueue_scripts and wp_enqueue_script() to enqueue Google Maps API function wp_mk_scripts() { if ( is_singular() ) { wp_enqueue_script( ‘wp-mk-maps-js’, ‘https://maps.googleapis.com/maps/api/js’, array( ‘jquery’ ), null, true ); wp_enqueue_script( ‘wp-mk-gmaps-function’, get_stylesheet_directory_uri() . ‘/js/maps.js’, array( ‘jquery’ ), null, … Read more

Google Maps API in wordpress

Figured it out!!!!! Since we get the SQL query result with the help of “$wpdb” object we can access each row’s attribute as an associative array. As a result there isn’t a need for “mysql_fetch_assoc()” and “mysql_query()” functions. Also we need to define “$wpdb” object, so we require “wp-config.php” file.

Display posts on a map

The GPS position is saved on two post meta fields: geo_latitude and geo_longitude. You can use these meta values to draw the posts as markers on a Google Maps. For example, using Google Maps API, you could have a template like this: <h1>Posts on map</h1> <div id=”map” style=”height: 400px;”></div> <script> // init map with the … Read more

Advanced Custom Fields – Google Map Won’t Render Unless Variable Dumped

Try this code: <div class=”map”> <?php global $post; $location = get_field(‘location’, $post->ID); ?> <div class=”acf-map”> <div class=”marker” data-lat=”<?php echo $location[‘lat’]; ?>” data-lng=”<?php echo $location[‘lng’]; ?>”></div> </div> </div> Sometimes in the template you’re loading this you don’t have the post that the field belongs to, so you can try to fetch it in the global $post … Read more