• I’m new to WordPress. The plugins for Google Maps don’t work for this application because they put the map into the content area of wordpress and I need it to be separate from that.

    I’ve created a couple of custom fields for latitude and longitude and want to pass those into the Google Map API code. The problem I’m having is that the Google Map API is javascript that runs in the header.php file of my template and is called in the body tag. But this is before the php code that queries the database and gets the particular record needed for this page. So, how can I pass the custom field values to the Google Map API code. Any help would be greatly appreciated.

Viewing 1 replies (of 1 total)
  • I had tried doing this once before, if you are trying to call for the custom fields you could create a new loop before the google js. To my knowledge it will go as follows:

    <$php global $lat; ?>
    <$php global $longt; ?>
    <?php if ( is_single() ) { ?>
    <?php $lat = get_post_meta($post->ID, 'Latitude', true); ?>
    <?php $longt = get_post_meta($post->ID, 'Longitude', true); ?>
    <?php } ?>
    <?php echo $lat; ?>
    <?php echo $longt; ?>

    The first two lines can be skipped.
    the third line starts the loop
    ‘Latitude’ and ‘Longitude’ in the 4 & 5th line is the name of the custom field.
    Line 6 closes the loop
    The last two lines call for the value in your google js.

    Hope this helps,

    Cheers!!

    Dheer

Viewing 1 replies (of 1 total)
  • The topic ‘Custom fields with Google Map’ is closed to new replies.