Support

Account

Home Forums Add-ons Flexible Content Field Flexible Content Field inside Clone Field

Solving

Flexible Content Field inside Clone Field

  • I am trying to access Flexible Content rows inside my Clone field and cant seem to get it to work. I have a Layout with the field name ‘fullscreen_callout’ which has a Clone subfield called ‘fullscreen_callout_clone’. That clone field uses the Group setting. the Fullscreen Callout Clone group has a Radio Button field (which I can access in my template file with no issues) and a Flexible Content field (‘callout_content’), but I cannot seem to access any of the values inside that Flexible Content Field.

    <?php if( get_row_layout() == 'fullscreen_callout' ): 
    include( 'template-parts/content--fullscreen-callout.php' );
    endif; ?>

    The above works correctly and the template-parts/content–fullscreen-callout.php file is loaded into the page.

    Then inside that PHP file I am trying to access the values of the Flexible Content Field with no luck. The subfield ‘background-color’ can be accessed but cannot seem to acess any of the rows inside ‘callout_content’. Is it possible to use Flexible Content field inside a CLone field? Nothing happens inside my if(have_rows(‘callout_content’) conditional?

    
    <?php $callout = get_sub_field('fullscreen_callout_clone');
    if ($callout) : 
        $color = $callout['background_color'];
        $layouts = $callout['callout_content'];
        if ($layouts) :  ?> 
    <section class="outer fullscreen--cta<?php if ($color == 'gray') : echo ' gray'; endif; ?>">
            <div class="container-fluid">
                 <div class="row">
                     <div class="col-xs-12 pb-0x">
                         <div class="shield"></div>
                     </div>
                 </div>
           </div>
           <?php if (have_rows('callout_content') :
               while (have_rows('callout_content') : the_row() ?>
                   <?php // Case: CTA Buttons. ?>
                <?php if( get_row_layout() == 'image' ):
                    $image = get_sub_field('image');
                    $caption = get_sub_field('caption'); ?>
                    <div class="container">
                        <div class="row">
                            <div class="col-xs-12 col-sm-8 col-sm-offset-2 pt-0x pb-3x">
                                <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
                   <?php endwhile; ?>
               <?php endif; ?>            
        </section>
    <?php endif ?>
  • The problem is that you use this to get the clone field

    
    $callout = get_sub_field('fullscreen_callout_clone');
    

    and then try to use this to get the show the layouts

    
    if (have_rows('callout_content') :
               while (have_rows('callout_content') : the_row() 
    

    You either need to deal with both of these using loops or array, you cannot mix them

    
    // loops
    if (have_rows('fullscreen_callout_clone')) {
      while (have_rows('fullscreen_callout_clone')) {
        the_row()
        $color = get_sub_field('background_color');
        if (have_rows('callout_content')) {
          while (have_rows('callout_content')) {
            the_row();
            //... etc
          }
        }
      }
    }
    

    OR

    
    // arrays
    $callout = get_sub_field('fullscreen_callout_clone');
    if ($callout) {
      $color = $callout['background_color'];
      $layouts = $callout['callout_content'];
      if ($layouts) {
        foreach ($layouts as $layout) {
          if ($layout['acf_fc_layout'] == 'image') {
            $image = $layout['image'];
            // .. etc
          }
        }
      }
    }
    
  • Perfect, as always John! Either solution solves my issue.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.