Support

Account

Home Forums Add-ons Repeater Field Post Object in Repeater only displaying first instance in loop

Helping

Post Object in Repeater only displaying first instance in loop

  • I am trying to do something that I thought should be relatively simple but is proving to be very tricky to pull off! I have a post object within a repeater field and for some reason the repeater field is only showing the first instance of the post object…

    ‘select_mix’ is my Repeater field and ‘mix_character_select’ is my sub field in the ‘select_mix’ Repeater and is the Post Object. The ‘mix_character_select’ Post Object has three fields, one of which in the code shown below is ‘mix_description’.

    Please find the code in question below…

    <?php if( have_rows('select_mix') ):
      while (have_rows('select_mix')) : the_row(); ?>
    
      <?php $post_object = get_sub_field('mix_character_select'); ?>
    
      <?php if( $post_object ): ?>
        <?php $post = $post_object; setup_postdata( $post ); ?>
          <h2><?php the_title(); ?></h2>
          <p>
            <?php the_field('mix_description'); ?>
          </p>
       <?php endif; ?>
    
      <?php endwhile;
    endif; ?>
    
    <?php wp_reset_postdata(); ?>

    So in the page where the select_mix Repeater field shows up, I select four ‘mix_character_selects’, so would expect to have four ‘mix_description’ fields come up on the front end. However only the first one appears.

    Not sure where to go from here, so any help would be greatly appreciated!

    Thanks in advance.

  • I’m not really sure how you’re even seeing one. If you have the post pbject field set up to allow multiple selections then it should be returning and array.

    
    <?php if( have_rows('select_mix') ):
      while (have_rows('select_mix')) : the_row(); ?>
    
      <?php $post_object = get_sub_field('mix_character_select'); ?>
    
      <?php if( $post_object ): ?>
        <?php 
    			foreach ($post_object as $post) { 
    				setup_postdata( $post ); ?>
    				<h2><?php the_title(); ?></h2>
    				<p>
    					<?php the_field('mix_description'); ?>
    				</p>
    				<?php 
    			} // end foreach post
    			endif; ?>
    
      <?php endwhile;
    endif; ?>
    
    <?php wp_reset_postdata(); ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Post Object in Repeater only displaying first instance in loop’ is closed to new replies.