Support

Account

Home Forums General Issues Trouble with resetting Reply To: Trouble with resetting

  • So i’m guessing it’s the following 2 field calls that are failing?

      <?php the_field("presentation_abstract"); ?>
                                        <p>
                                        	<a href="<?php the_field("presentation_download_file"); ?>" target="_blank" class="arrow">Download</a>
                                        </p>
                                    </section>	

    If this is the case then a work around would be simple, set those fields as variables further up the page, and then simply call the variable.

    <!-------------------MAIN PAGE LOOP------------------------->
      <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>  
    	
            <div id="main" class="clearfix">
    	               
    	        <?php if(trim(get_field("headline_override")) != ""): ?>
    	        	<h1><?php the_field("headline_override"); ?></h1>
    				<?php else: ?>
    	        	<h1><?php the_title(); ?></h1>
    	        <?php endif; ?>                                    
    	        <article>
    			<?php the_content(); ?>   
    	           	<div id="presentations"> 
                       	
                       	
    <!-------------------CUSTOM WP_QUERY LOOP------------------------->                   	
                       	
    				<?php
                        
    	                        // The Query
    	                        $args = array(
    	                            'post_type'	=> 'presentations',
    	                            'posts_per_page'     => -1,
    	                            'order' => 'DESC',
    	                            'orderby' => 'presentation_date',						
    	                            'post_status' => 'publish',
    					'meta_key' => 'presentation_date',
    					'meta_query' => array(
    						array(
    						'key' => 'archived_presentation',
    						'value' => 'true',
    						'compare' => '!='
    					)
    				)							
    	                        );						
                            $custom_loop = new WP_Query($args);			
                            #echo $custom_loop->request; 	
    						
    			$previous_year = "";						
                            
                            // The Loop
                            if( $custom_loop->have_posts() ): ?>
                                <?php while( $custom_loop->have_posts() ): $custom_loop->the_post(); ?>
                                	<?php 
    					$date = DateTime::createFromFormat('Ymd', get_field('presentation_date'));
    					$current_year = $date->format('Y');		
    					
    					if($previous_year != $current_year) { echo "<p>" . $current_year . "</p>";}
    					$previous_year = $current_year;
    				?>
                                    <section>
                                    <h2><a href="<?php the_field("presentation_download_file"); ?>" target="_blank"><?php the_title(); ?></a></h2>
                                       
    <?php $presentationDownloadFile = get_field("presentation_download_file");
    $presentationAbstract = get_field("presentation_abstract"); ?>
                                    <p>
    <!-------------------FIRST ACF RELATIONSHIP LOOP THAT BREAKS THINGS------------------------->                                  
    					<?php
    					#--------- research center
    					$posts = get_field('research_center');                         
    					if( $posts ): 
    						foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    							setup_postdata($post); ?>
    							<strong>Lead Research Center:</strong> <a href="/about/#center-<?php echo $post->ID; ?>"><?php the_title(); ?></a><br />
    						<?php endforeach; 
    						wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly 
    					endif; 						
    					
    					#--------- presenters											
                                            $posts = get_field('presenters');                         
                                            if( $posts ): ?>
                                                <strong>Presenter(s):</strong>
    						<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    	                                               setup_postdata($post); ?>
    	                                                <a href="/about/staff/#staff-<?php echo $post->ID; ?>"><?php the_title(); ?></a>
    	                                        <?php endforeach; 
                                                wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly 
                                            endif; 	                                    										
    										?>                                    
                                        </p>
                                        <?php echo $presentationAbstract; ?>
                                        <p>
                                        	<a href="<?php echo $presentationDownloadFile; ?>" target="_blank" class="arrow">Download</a>
                                        </p>
                                    </section>			                                                                                                     
                                <?php endwhile; ?>                           
                            <?php endif;
                            
                            // Reset Query
                            wp_reset_postdata(); ?>
                                                                                              		                     
    			</div><!-- / #presentations -->
                                                           
                	</article><!-- article -->
                </div> 
            </div>                                              
        <?php endwhile; ?>            

    p.s. I don’t really get what you are trying to do so I can’t comment on whether the nested loops are required or not, but I think for single pages your first loop shouldn’t be required. I might be wrong though 😉