Support

Account

Home Forums ACF PRO Post Object within Repeater Not Working

Helping

Post Object within Repeater Not Working

  • 
    <?php if ( have_rows( 'tabs' ) ) : $i = 0; ?>
      		<?php while ( have_rows( 'tabs' ) ) : the_row(); $i++; ?>
        		<div class="tabContent<?php if ( $i == 1 ) : ?> active<?php endif; ?>" data-tabid="block<?php echo $GLOBALS['block_num']; ?>tab<?php echo $i; ?>">
              <?php
                $tab_content = get_sub_field( 'tab_content' );
              ?>
    
              <?php if ( $tab_content ) : ?>
                <?php foreach ( $tab_content as $post ) : setup_postdata( $post ); ?>
                  <?php the_content(); ?>
                <?php endforeach; wp_reset_postdata(); ?>
              <?php endif; ?>
        		</div>
      	  <?php endwhile; ?>
      	<?php endif; ?>
    

    $tab_content is a ACF Post Object within a repeat and it will display the first item, then no matter what I try it will always break the repeater loop and not display the second item in the repeater ‘tabs’

    I’ve tried:
    – Using a single post object instead of multiple
    – I’ve tried using a WP Query
    – I’ve tried parse_blocks and render_block

    It always won’t display anything after the first item.

    I’m trying to create a repeater for tabs, and display a custom post type (reusable content) as a post object within those tabs.

  • This sounds like a nested query issue and wp_reset_postdata() is resetting to the main post rather than the post of the nested query.

    This can be corrected by using $nested_query->reset_postdata(); if that is the case.

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

You must be logged in to reply to this topic.