Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<ul class="footer_banner_box_container clearfix">
    <div id="text-4" class="widget widget_text">
        <h3 class="box_header">Our Doctors</h3>
        <div class="textwidget">
            <h3 id="our-docs" style="margin: 10px 20px; padding: 20px; color: #002664;">Our team includes an array of trained experts, who can make critical decisions regarding care that typically would require multiple office visits.</h3>
            <br />
            <ul class="bxslider">
                    <?php
                $args = array('post_type' => 'Doctors', 'orderby' => 'rand');
                $query = new WP_Query( $args );
                ?>
                <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
                    <?php if ( has_post_thumbnail() ): ?>
                        <a href="<?php the_permalink(); ?>">
                        <div class="view">
                            <li><?php the_post_thumbnail( array(160,225) ); ?></li>
                            <div class="mask">
                            <h4><?php the_title(); ?></h4>
                            </div>
                            </div>
                        </a>
                    <?php endif; ?>
                <?php endwhile; endif;  ?>
            </ul>
        </div>
    </div>
</ul>
<ul class="footer_banner_box_container clearfix">
    <div id="medicenter_contact_details-4" class="widget contact_details_widget">
        <h2 class="box_header"><?php the_field('hospital_name'); ?></h2>
        <ul class="footer_contact_info_container clearfix">
            <li class="footer_contact_info_row">
                <div class="footer_contact_info_left"><?php the_field('hospital_address_line_1'); ?></div>
                <div class="footer_contact_info_right"></div>
            </li>
            <li class="footer_contact_info_row">
                <div class="footer_contact_info_left"><?php the_field('hospital_address_line_2'); ?></div>
                <div class="footer_contact_info_right"></div>
            </li>
            <li class="footer_contact_info_row">
                <div class="footer_contact_info_left"><?php the_field('hospital_phone_number'); ?></div>
                <div class="footer_contact_info_right"></div>
            </li>
        </ul>
    </div>
    <div id="footer_content_1" class="widget widget_text">
        <div class="textwidget">
            <p style="color: #002664;"><?php the_field('footer_content_1'); ?></p>
        </div>
    </div>
    <div id="footer_content_2" class="widget widget_text">
        <div class="textwidget">
            <?php the_field('footer_content_2'); ?>
        </div>
    </div>
</ul>

In my footer template, I'm trying to recreate preexisting widgets. I have a WP_Query setup to call a custom post type, and then I'm passing the post_thumbnails to a jQuery carousel. Below that I have another widget area that I'm trying to make more dynamic by using Advanced Custom Fields to fill the values. However, when I have my footer template structured this way (as it has to be), the php calls to get the custom field values do not get made. When I have the second footer_banner_box_container above the first one it works but as it sits it does not. Could be the theme but I'm really coming up empty. Any help would be appreciated

share|improve this question
2  
Please clarify what you expect and what actually happens. –  kraftner Jun 6 at 18:33

2 Answers 2

up vote 0 down vote accepted

Your code in the second footer_banner_box_container is trying to fetch those fields from the last post in the custom post type query directly above it, because that was the last value given to the global $post when $query->the_post() was called in that loop.

I assume you want the fields from the main query and not that secondary query, so you must add wp_reset_postdata(); after the loop of any additional queries, to restore $post to its original value. That way, any template tags that internally use the value of the current $post will use the correct data and give expected results.

share|improve this answer
    
this works. thanks! –  universalshrew Jun 6 at 19:02

You need to use wp_reset_postdata(); after the loop so the custom field data is again fetched from the original post data.

Have a look at the codex for more details.

share|improve this answer
    
thanks for the response! –  universalshrew Jun 6 at 19:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.