I hope I get some help with get_template_part function.
- my starting point is a contact-us template (it's got map+address+emailform) that stores data in the database
- my other template is where I have put get_template_part( 'contact-us' ).
If taken on its own, the contact-us page works fine (showing data and emailform) but when inserted in the other template then the map+address data are not outputted (yet emailform is working).
What can the problem be? Herewith is the contact-us code:
<?php
/*
* Template Name: Contact Us Page
* Description: A Contact Us Page Template for careers theme
*/
get_header(); ?>
<?php include(locate_template('top-header.php')); ?>
<div id="page-content">
<div class="container">
<div class="contenitore">
<div class="page-content">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php
$address = get_post_meta($post->ID, '_meta_box_contact_address', true);
?>
<div class="contact-us">
<div class="row">
<div class="col-md-6">
<center><h3><?php _e('Our', 'globo'); ?><strong><?php _e(' Hq', 'globo'); ?></strong></h3></center>
<div class="contacy-us-map-section">
<div id="contact_map_canvas">
</div>
</div> <!-- end .map-section -->
<div class="row">
<div class="col-sm-6">
<h5><?php _e('Address Details', 'globo'); ?></h5>
<div class="address-details clearfix">
<i class="fa fa-map-marker"></i>
<?php echo apply_filters('the_content',$address); ?>
</div>
<div class="address-details clearfix">
<i class="fa fa-phone"></i>
<p>
<span><strong><?php _e('Phone:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_phone', true)); ?></span>
<span><strong><?php _e('Fax:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_fax', true)); ?></span>
</p>
</div>
<div class="address-details clearfix">
<i class="fa fa-envelope-o"></i>
<p>
<span><strong><?php _e('E-mail:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_email', true)); ?></span>
<span><span><strong><?php _e('Website:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_website', true)); ?></span></span>
</p>
</div>
</div>
<div class="col-sm-6">
<h5><?php _e('Openig Hours', 'globo'); ?></h5>
<div class="address-details clearfix">
<i class="fa fa-clock-o"></i>
<p>
<span><strong><?php _e('Mon-Fri:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_opening_mon_fri', true)); ?></span>
<span><span><strong><?php _e('Saturday:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_opening_sat', true)); ?></span></span>
<span><strong><?php _e('Sunday:', 'globo'); ?></strong> <?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_opening_sun', true)); ?></span>
</p>
</div>
</div>
</div> <!-- end .nasted row -->
</div> <!-- end main grid layout -->
<div class="col-md-6">
<center><h3><?php _e('Message', 'globo'); ?><strong><?php _e(' Us', 'globo'); ?></strong></h3></center>
<div class="contact-form">
<?php echo do_shortcode(get_post_meta($post->ID, '_meta_box_contact_form_widget', true)); ?>
</div> <!-- end .contact-form -->
</div> <!-- end main grid layout -->
</div> <!-- end .row -->
</div> <!-- end .contact-us -->
<?php endwhile; endif; ?>
<script>
var txt = '<?php echo esc_url(get_template_directory_uri()); ?>';
(function($) {
setTimeout(function(){
var myMap = $("#contact_map_canvas").goMap({
maptype: 'ROADMAP',
zoom: 10,
scrollwheel: true,
markers: [{
// latitude: 37.793100669930396,
latitude: '<?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_lat', true)); ?>',
// longitude: -122.41769313812256,
longitude: '<?php echo esc_attr(get_post_meta($post->ID, '_meta_box_contact_lon', true)); ?>',
icon: txt+'/assets/img/content/map-marker-company.png',
html: '<?php bloginfo('name'); ?>'
}]
});
google.maps.event.trigger(myMap , 'resize');
}, 3000);
// console.log(txt);
}(jQuery));
</script>
</div> <!-- end .page-content -->
</div> <!-- end .contenitore -->
</div> <!-- end .container -->
</div> <!-- end #page-content -->
<?php get_footer(); ?>