Support

Account

Home Forums Add-ons Repeater Field Post object within a nested Repeater

Unread

Post object within a nested Repeater

  • I’m trying to list the college that each academic staff member works at, within each course. The truncated code below is should return a post object (college) within a repeater (academics), which nests within another repeater (course). But my code just returns the current post, and not the post in the post object field. Not sure why though.

    <?php if( have_rows( 'courses' ) ): // My first repeater ?>
    	
    	<?php while( have_rows('courses') ): the_row(); ?>
    
    			<?php if( have_rows( 'academics' ) ): // My second repeater ?>
    
    			<ul>
    
    				<?php while( have_rows( 'academics' ) ): the_row();
    
    				$college = get_sub_field('college'); // My post object field ?>
    					
    					<li>
    				
    						<?php if( $college ) :
    							        
    							$post = $post_object; // This is where I set the post to the post object, so I can setup post data
    
    							setup_postdata($post);
    
    						?>
    							
    								<div class="your-post"> 
    									
    									<?php the_title(); // This should return the title of the college post object ?>
    									
    								</div>
    							
    							<?php wp_reset_postdata(); ?>
    							
    							<?php endif; ?> 
    					</li>
    						
    				<?php endwhile; ?>
    				
    				</ul>
    
    			<?php endif; ?>
    
    	<?php endwhile; ?>
    
    <?php endif; ?>

    Do you know what’s wrong with my code?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.