Support

Account

Home Forums ACF PRO The foreach code is returning too much.

Solved

The foreach code is returning too much.

  • Hello.
    I used post object in repeater. I can pull data. I added 2 pieces of data. but it pulls each data 24 times. The codes are below. Where am I doing wrong?

    Link: https://www.icoanaliz.com/ico/authtrail-aut/

    	<?php 
    	// check for rows (parent repeater)
    	if( have_rows('danismanlar') ): 
    	?>
    	<div class="stm_single_ico_part stm_single_ico__market">
    		<i class="stm-short_review stm_single_ico_part__icon stc"></i>
    			<div class="stm_single_ico_part__title h4">
    			<?php esc_html_e('Advisors', 'crypterio'); ?>
        		</div>
    			<?php while ( have_rows('danismanlar') ) : the_row(); ?>
    		<div >
    			<div class="tmm">
    				<div class="tmm_5_columns tmm_wrap tmm_plugin_f">
    				<span class="tmm_two_containers_tablet"></span>
    					<div class="tmm_container">
    					
    						<?php
    						$featured_posts = get_sub_field('personel'); 
    						//$featured_posts = get_field('personel');
    						if( $featured_posts ): ?>
    
    						<?php //$post = $featured_posts; //setup_postdata( $post ); 
    						foreach( $featured_posts as $post ): 
    						
    						// Setup this post for WP functions (variable must be named $post).
    						setup_postdata($post); ?>
    						
    						
    						
    						<div class="tmm_member" style="border-top:#333333 solid 5px;" >
    							<div class="tmm_photo tmm_pic_enedex_0" style="background-image: url(<?php echo the_post_thumbnail_url(); ?>); margin-left: auto; margin-right:auto; background-size:cover !important;"></div>
    							<div class="tmm_textblock">
    								<div class="tmm_names"><span class="tmm_fname"><a href="<?php the_permalink(); ?>" target="_blank"><?php echo esc_html( $post->post_title ); ?></a></span> </div>
    								<div class="tmm_job">
    								<?php 
    								// loop through rows (parent repeater)
    								while( have_rows('sosyal_medya_hesaplari_d') ): the_row(); 
    								?>
    								<a target="_blank" class="tmm_sociallink" href="<?php the_sub_field('link_d'); ?>" title=""><img alt="" src="https://www.icoanaliz.com/logo/member_links/<?php the_sub_field('sosyal_medya_hesabi_d');?>.png" /></a>
    								<?php endwhile;?>
    								</div>
    								<div class="tmm_scblock">
    									<?php the_sub_field('personelin_gorevi');?>
    								</div>
    								
    							</div>
    						</div>
    
    									<?php endforeach; ?>
    
    			<?php 
    			// Reset the global post object so that the rest of the page works correctly.
    			wp_reset_postdata(); ?>
    		<?php endif; ?>
    
    						<span class="tmm_two_containers_tablet"></span>
    						<div style="clear:both;"></div>
    
    					</div>
    				</div>
    			</div>
    		</div>
    		<?php endwhile; ?>
    	</div>
    	<?php endif; // if( get_field('to-do_lists') ): ?>
    
    
  • I had to use while. I solved the problem.

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

You must be logged in to reply to this topic.