Support

Account

Home Forums Front-end Issues Nested Post Objects

Unread

Nested Post Objects

  • Hello!
    I am having trouble getting nested post objects to work correctly. The flow is: page–>Repeater–>Post Object–>Post Object. The sample below does return the information I want, however it only returns one “Case Study” post object despite having multiple in the repeater. Any help would be greatly appreciated.

    <?php elseif( get_row_layout() == 'case_study_carousel_layout' ):?>
    
        <div id="caseStudyCarousel" class="carousel slide">
            <div class="carousel-inner">
                <?php if( have_rows('case_study_repeater') ):?>
                    <?php $num = -1;?>
                    <?php while ( have_rows('case_study_repeater') ) : the_row();?>
                        <?php $num++?>
                        <?php $post_object = get_sub_field('case_study');?>
                        <?php if( $post_object ): ?>
                            <?php $post = $post_object;?>
                            <?php setup_postdata( $post );?>
                                <?php
                                if ($num == 0) {
                                    $class = "active";
                                } else {
                                    $class = "";
                                }
                                ?>
                                <?php if( have_rows('case_study_teaser_group') ):?>
                                    <?php while( have_rows('case_study_teaser_group') ): the_row();?>
                                        <div class="carousel-item <?php echo $class;?>" class="wave carousel-item <?php echo $class;?>">
                                            <div class="row">
                                                <div class="wave col-md-6" style="background:linear-gradient(90deg, <?php the_sub_field('gradient_start'); ?>, <?php the_sub_field('gradient_end'); ?>);">
                                                    <?php $image = get_sub_field('image'); ?>
                                                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                                </div>
                                                <div class="col-md-6">
                                                    
                                                    <?php $post_objectC = get_sub_field('client');?>
                                                    <?php if( $post_objectC ):?>
    
                                                    	<?php $post = $post_objectC;?>
                                                    	<?php setup_postdata( $post );?>
                                                        <div>
                                                        	<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                                        </div>
                                                        <?php //wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
                                                    <?php endif; ?>
                                                    
                                                    <?php the_title();?><br />
                                                    <?php the_sub_field('headline'); ?><br />
                                                    <?php the_sub_field('description'); ?>
                                                </div>
                                            </div>
                                        </div>
                                    <?php endwhile; ?>
                                <?php endif; ?>
                            <?php wp_reset_postdata(); ?>
                        <?php endif; ?>
                    <?php endwhile; ?>
                <?php endif; ?>
            </div>
        </div>
Viewing 1 post (of 1 total)

The topic ‘Nested Post Objects’ is closed to new replies.