Support

Account

Home Forums General Issues Relationships within repeater within flexible content

Helping

Relationships within repeater within flexible content

  • Hello,
    I have a relationship field within a Flexible Content > Repeater field. If I add one instance of this, it shows up on my page (template code below).

    However, if I add a second instance of this in the admin, the second one does not show up.

    It is basically a field that I can pick and choose which posts I want to show.. so it relates blog entries (default posts – not any CPT).

    Any pointers? Help? How can I get multiple instances?

    
    <?php
    	if( have_rows('content_blocks') ):
    		while ( have_rows('content_blocks') ) : the_row();
    			
    			// SHOW POSTS
    			if( get_row_layout() == 'show_posts' ):
    				echo '<div class="column-posts section>';
    					$posts = get_sub_field('select_posts');
    					if( $posts ):
    						foreach( $posts as $post):
    							echo '<div class="column-post columns>';
    								setup_postdata($post);
    								echo '<div class="image">';
    									the_post_thumbnail(' ');
    								echo '</div>';
    								echo '<p class="post-title">';
    									the_title();
    								echo '</p>';
    							echo '</div>';
    						endforeach;
    					endif;
    				echo '</div>';
    			endif;
    			// END SHOW POSTS
    
    		endwhile;
    	endif;
    ?>
    
  • I don’t see a call to wp_reset_postdata() in your code. This will cause unpredictable errors. https://www.advancedcustomfields.com/resources/relationship/

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

You must be logged in to reply to this topic.