Support

Account

Home Forums Front-end Issues How to display custom post with acf fields from within repeater in flexible cont Reply To: How to display custom post with acf fields from within repeater in flexible cont

  • I am bit closer to my goal. At this moment I just can’t access acf fields from the posts listed in the page via repeater and flexi content. Weird …

    This is my new code that works.
    Please see attached screens of my setup.

    <ul class="pageBodyKanaly">
    								<?php // check if the flexible content field has rows of data ?>
    								<?php if( have_rows('kanaly_telewizyjne_na_stronie') ): ?>
    								
    									<?php // loop through the rows of data ?>
    									<?php while ( have_rows('kanaly_telewizyjne_na_stronie') ) : the_row(); ?>
    										<li class="kanalElement">
    											<?php // check current row layout ?>
    											<?php if( get_row_layout() == 'kategoria_kanalu' ):  ?>
    												
    												<div class="kategoriaKanalow">
    													<?php if( get_sub_field('nazwa_kategorii_kanalu')): ?>
    														<h2><?php the_sub_field('nazwa_kategorii_kanalu'); ?></h2>
    													<?php endif; ?>
    												</div>
    												
    												<section class="kanalyBody">
    													<?php if( have_rows('programy_lista') ): ?>
    														<ul id="kanaly">
    															<?php while ( have_rows('programy_lista') ) : the_row(); ?>   
    																<li>
    																	<?php
    																		$post_objects = get_sub_field('kanal');
    																		if( $post_objects ): ?>
    																			<ul>
    																			<?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
    																				<?php setup_postdata($post); ?>
    																				<li>
    																					<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    																					<?php the_content(); ?>
    																					<?php if( get_sub_field('klasa_obrazka')): ?>
    																						<h5><?php the_sub_field('klasa_obrazka'); ?></h5>
    																					<?php endif; ?>
    																				</li>
    																			<?php endforeach; ?>
    																			</ul>
    																			<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    																		<?php endif; ?>
    																</li>
    															<?php endwhile; ?>
    															</ul>
    													<?php endif; ?>
    												</section>
    											<?php endif; ?>
    										</li>
    									<?php endwhile; ?>
    							</ul>