Support

Account

Home Forums Add-ons Repeater Field Wrong content appearing…

Solved

Wrong content appearing…

  • Ok, first, I’m super tired right now. I mention this because I feel like I should be immediately seeing why my code isn’t working quite right, but I just don’t see it.

    I’m using a Repeater Field to with a post object sub-field (have tried it with the relationship sub-field instead and I get exactly the same result), with Pages chosen. This field is assigned to my Options page.

    On my Options page I have selected 5 pages that are being displayed on my homepage in a horizontal scrolling pane setup. Mostly works well (except it doesn’t scroll in FF and I don’t know why right now). However, even though I’ve got the right titles showing up in the right areas, for some reason, the content for each page appears in the next panel from where it belongs. Not sure what I’m doing wrong.

    This is generally how it’s laying out:

    Chapter 1
    Correct Title
    No content

    Chapter 2
    Correct Title
    Content from Chapter 1

    Chapter 3
    Correct Title
    Content from Chapter 2

    See what I mean?

    <?php if( have_rows('home', 'option') ): $i = 0;
    						while( have_rows('home', 'option') ): the_row(); $i++;
    							$post_object = get_sub_field('choose_pages');
    							$post_object_icon = get_sub_field('choose_icon');
    							
    							$post = get_post($p->ID);
    							setup_postdata( $post, $more_link_text, $stripteaser );
    						
    							if( $post_object ):
    								foreach( $post_object as $p ): ?>
    								<article class="hs-content" id="chapter<?php echo $i; ?>">
    									<div class="hs-inner">
    										<h2>Chapter <?php echo $i; ?>.</h2>
    										<h3><?php echo get_the_title( $p->ID ); ?></h3>
    										
    										<div class="container-fluid">
    											<div class="row">
    												<?php the_content($p->ID); ?>
    											</div>
    										</div>
    									</div>
    								</article>
    								<?php endforeach;
    							endif;
    							
    							wp_reset_postdata( $post );
    							
    						endwhile;
    					endif; ?>

    To be honest, I’m not even sure if this is an ACF loop issue or if I should instead be asking on WordPress itself. My brain is seriously fried right now.

  • Hiya,

    You’ve got 2 lines misplaced.

    
    <?php if( have_rows('home', 'option') ): $i = 0;
    						while( have_rows('home', 'option') ): the_row(); $i++;
    							$post_object = get_sub_field('choose_pages');
    							$post_object_icon = get_sub_field('choose_icon');
    							
    							// these 2 lines should be in the loop
    							//$post = get_post($p->ID);
    							//setup_postdata( $post, $more_link_text, $stripteaser );
    						
    							if( $post_object ):
    								foreach( $post_object as $p ): 
    									
    									
    									// move the lines here
    									$post = get_post($p->ID);
    									setup_postdata( $post, $more_link_text, $stripteaser );
    									
    									
    								?>
    								<article class="hs-content" id="chapter<?php echo $i; ?>">
    									<div class="hs-inner">
    										<h2>Chapter <?php echo $i; ?>.</h2>
    										<h3><?php echo get_the_title( $p->ID ); ?></h3>
    										
    										<div class="container-fluid">
    											<div class="row">
    												<?php the_content($p->ID); ?>
    											</div>
    										</div>
    									</div>
    								</article>
    								<?php endforeach;
    							endif;
    

    Take a break and rest your brain 🙂

  • I love you. Thank you. So obvious. But yes, completely brain dead today.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Wrong content appearing…’ is closed to new replies.