Skip to main content
added 30 characters in body
Source Link
Krzysiek Dróżdż
  • 25.5k
  • 9
  • 53
  • 74

I am using the following to display google maps using hotel_address custom field.

<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=<?php the_field('hotel_address'); ?>&amp;iwloc=&amp;output=embed"></iframe><br /><small>

And it is working fine, getting hotel address and displaying a map, however I would like to hide this is hotel_address is blank.

I have tried the following

<?php
    $map = get_post_meta($post->ID, 'hotel_address', true);
    if ( $map ) {
        echo '<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q="'.$map.'"&amp;iwloc=&amp;output=embed"></iframe><br /><small>';
        echo '';
    }
?>

And can confirm that $map is picking up the address by using echo $map however it just shows a blank box without any map.

Any ideas? Richard

I am using the following to display google maps using hotel_address custom field.

<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=<?php the_field('hotel_address'); ?>&amp;iwloc=&amp;output=embed"></iframe><br /><small>

And it is working fine, getting hotel address and displaying a map, however I would like to hide this is hotel_address is blank.

I have tried the following

<?php
$map = get_post_meta($post->ID, 'hotel_address', true);
if( $map) {
echo '<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q="'.$map.'"&amp;iwloc=&amp;output=embed"></iframe><br /><small>';
echo '';
}
?>

And can confirm that $map is picking up the address by using echo $map however it just shows a blank box without any map.

Any ideas? Richard

I am using the following to display google maps using hotel_address custom field.

<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=<?php the_field('hotel_address'); ?>&amp;iwloc=&amp;output=embed"></iframe><br /><small>

And it is working fine, getting hotel address and displaying a map, however I would like to hide this is hotel_address is blank.

I have tried the following

<?php
    $map = get_post_meta($post->ID, 'hotel_address', true);
    if ( $map ) {
        echo '<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q="'.$map.'"&amp;iwloc=&amp;output=embed"></iframe><br /><small>';
        echo '';
    }
?>

And can confirm that $map is picking up the address by using echo $map however it just shows a blank box without any map.

Any ideas? Richard

Source Link

Cannot Hide Google Map if custom field is blank

I am using the following to display google maps using hotel_address custom field.

<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=<?php the_field('hotel_address'); ?>&amp;iwloc=&amp;output=embed"></iframe><br /><small>

And it is working fine, getting hotel address and displaying a map, however I would like to hide this is hotel_address is blank.

I have tried the following

<?php
$map = get_post_meta($post->ID, 'hotel_address', true);
if( $map) {
echo '<iframe width="440" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q="'.$map.'"&amp;iwloc=&amp;output=embed"></iframe><br /><small>';
echo '';
}
?>

And can confirm that $map is picking up the address by using echo $map however it just shows a blank box without any map.

Any ideas? Richard