Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Getting google map to work in single post sidebar WordPress

Hi,

I have a code that have not work.

Basically, I want to embed a google map in the sidebar of single post (custom post type). The map address is obtained from the custom field "Addr" of the specific current post.

I understand that I need to use the custom field outside the loop. I thinking I am not able to tell the code to use the "current post ID" to extract its custom field key value.

This is the code I have.
<?php
global $post;
$mapid = $post->ID;

$var = get_post_custom_values('Addr', $mapid);
if ($var == '')
{ }
else { echo do_shortcode( '[googlemaps addr="' . $var . '"]'); } ?>

I am using headwaytheme whereby I use php leaf on the sidebar to add the above code.

Please help. thanks

Answers (3)

2012-09-29

Martin Pham answers:

try this



<?php
global $post;
$var = get_post_meta($post->ID, 'Addr', true);
if ($var)
{
echo do_shortcode( '[googlemaps addr="' . $var . '"]');
}
?>


wan comments:

Its not working.


Martin Pham comments:

please paste googlemaps shortcode function (or plugin name) and custom meta value


wan comments:

I am using myreviewplugin, that come with google map embed with shortcode option.

I have tested this code before within the single post and it is working.
<div id="googlegallery">
<?php $var = get_post_meta(get_the_id(), 'Addr', true);
if ($var == '')
{ }
else { echo do_shortcode( '[googlemaps addr="' . $var . '"]'); } ?>
</div><!--googlegallery-->

But I will like to embed it into the sidebar instead. I guess it is out of the loop that is causing the problem.


wan comments:

see the image for my address.