Support

Account

Home Forums General Issues Post Object / foreach creating 24 duplicates

Helping

Post Object / foreach creating 24 duplicates

  • I have a Group that contains 2 Text fields and 1 Repeater. And inside the Repeater is a Post Object. Like this:

    
    Our Partners / 'our_partners' (Group)
      ∟ Title / 'title' (Text)
      ∟ Intro / 'intro' (Text)
      ∟ Partners / 'partners' (Repeater)
          ∟ Partner / 'partner' (Post Object - Filter by Post Type: Partner)
    

    The CPT (partner) which only has the normal WP page title and an ACF Image field (‘logo’).

    I can get the correct selections to display both the title and the image, but it also seems to be returning 23 other semi-empty DIVs on top.

    Here is my current code:

    
    <div class="row" id="our_partners">
    	<div class="col">
    
    		<?php $our_partners = get_field('our_partners'); if( $our_partners ): ?>
    			<h1 class="title"><?php echo $our_partners['title']; ?></h1>
    			<div class="centre"><?php echo $our_partners['intro']; ?></div>
    
    			<?php if( have_rows( 'our_partners' ) ): ?>
    				<?php while( have_rows( 'our_partners' ) ): the_row(); ?>
    
    					<div class="squares">
    
    						<?php while( have_rows( 'partners' ) ): the_row(); ?>
    							<?php $partner = get_sub_field('partner'); if( $partner ): ?>
    
    								<?php foreach( $partner as $post ): ?>
    									<div class="square">
    										<img src="<?php echo get_field( 'logo' ); ?>" alt="<?php echo esc_html( $partner->post_title ); ?>">
    									</div>
    								<?php endforeach; ?>
    
    							<?php endif; ?>
    						<?php endwhile; ?>
    
    					</div>
    
    				<?php endwhile; ?>
    			<?php endif; ?>
    
    		<?php endif; ?>
    
    	</div>
    </div>
    

    And here’s what it’s returning:

    
    <div class="squares">
    	<div class="square"><img src="https://THE_FIRST_IMAGE_PATH.png" alt="THE_FIRST_PAGE_TITLE"></div>
    	<div class="square"><img src="" alt="THE_FIRST_PAGE_TITLE"></div>
    	<div class="square"><img src="" alt="THE_FIRST_PAGE_TITLE"></div>
    	<div class="square"><img src="" alt="THE_FIRST_PAGE_TITLE"></div>
    	(and another 20 of these)
    	<div class="square"><img src="https://THE_SECOND_IMAGE_PATH.png" alt="THE_SECOND_PAGE_TITLE"></div>
    	<div class="square"><img src="" alt="THE_SECOND_PAGE_TITLE"></div>
    	<div class="square"><img src="" alt="THE_SECOND_PAGE_TITLE"></div>
    	<div class="square"><img src="" alt="THE_SECOND_PAGE_TITLE"></div>
    	(and another 20 of these)
    </div>
    

    So technically it’s working. I just need some assistance to get all the excess ones gone.

    Many thanks in advance for any help given.

  • Delhi Institute of Digital Marketing (DIDM)

    Delhi Institute of Digital Marketing makes our candidates gratifying when it comes to infusing skills with practical knowledge and recent trends in the industry. We are a reputed and the best digital marketing institute in Gurgaon & across India. By MSME | ISO Certified.

    We provide online digital marketing course program in Gurgaon, Haryana. DIDM Covers almost every part of haryana. In online mode – DIDM Gurgaon again provide all three types of course Master in Digital Marketing Course | Advanced in Digital Marketing Course | Customized in Digital Marketing Course. The online course curriculumn design in such a way that every one can easily understand and same time student impliment the core concepts of Digital Marketing in practical way.

    Visit us at,
    https://www.didm.in/digital-marketing-course-in-gurgaon

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

You must be logged in to reply to this topic.