Home Forums Add-ons Flexible Content Field Flexible Content not rendering on frontend


Flexible Content not rendering on frontend

  • I have the following structure in ACF:

    relevant (group)
    content_boxes (repeater)
    content (flexible content)
    new_article (layout 1)
    new_html (layout 2)

    And my code to display some of it goes like this:

    <?php $relevant = get_field('relevant') ?>
    	<?php $content_boxes = $relevant['content_boxes'] ?>
    	<?php if ($content_boxes): ?>
    	<div class="cs-relevant-wrap">
    		<div class="container">
    			<h2><?php echo $relevant['heading'] ?></h2>
    			<div class="relevant-content-list">
    			<?php foreach ($content_boxes as $content_box): ?>
    				<div class="content-list-item col-<?php echo $content_box['column_width'] ?>">
    					<?php if( have_rows('content') ): ?>
       						<?php while ( have_rows('content') ) : the_row();?>
            					<?php if( get_row_layout() == 'new_article' ):
               						 $title = get_sub_field('article_title');?>
    							<h3><?php echo $title ?></h3>
           						<?php elseif( get_row_layout() == 'new_html' ): 
                					$html_block = get_sub_field('block_editor');?>
    							<?php echo $html_block; ?>
            					<?php endif;?>
       						<?php endwhile;?>
    					<?php else :?>
    					<?php endif;?> 
    			<?php endforeach ?>
    	<?php endif ?>

    It will render up until the flexible content if statements, but acts as if there is no data in the flex content fields (there is). Am i missing something obvious?

  • You cannot combine

    get_field('repeater || group || flexible conentent')



    when dealing with sub field of any kind.

    Everything is in the returned array here

    $relevant = get_field('relevant');

    and you must deal with looping over that array

    $content_boxes = $relevant['content_boxes'] 
    $content_rows = $content_boxes['content'];
    foreach ($content_rows as $content) {
      if ($content['acf_layout'] == 'new_article') {
         $title = $content['article_title'];

    Or you must start with and use have_rows() throughout

    if (have_rows('relevant')) {
      while (have_rows('relevant')) {
        if (have_rows('content_boxes')) {
          while (have_rows('content_boxes')) {
            if (have_rows('content')) {
              while (have_rows('content')) {
  • Thank you for the reply. I’ve modified my code using the first solution and I think my the only thing that threw me was

      if ($content['acf_layout'] == 'new_article') {
         $title = $content['article_title'];

    I don’t think [‘acf_layout’] is meant to be the flexible contents ID, since thats been redefined by a variable earlier on and it doesn’t seem to be an ACF selector. I don’t think I understand what that is meant to be?

  • going to be honest with you, I’m not sure of the index for the array value that holds the layout off the top of my head. You might want to try outputting the array to make sure.

    echo '<pre>'; print_r($content); echo '</pre>';
  • You were very close!

    This got it working for me, thanks so much!

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

You must be logged in to reply to this topic.