...
Tutorials, Wordpress

How to use ACF flexible content fields?

28 January 2019

The ACF flexible content field is essential a wrapper for a group of layouts, so to loop through the layouts and target the sub field values, you must make use of a few extra functions.

Basic loop example :
<?php

// check if the flexible content field has rows of data
if( have_rows('flexible_content_field_name') ):

     // loop through the rows of data
    while ( have_rows('flexible_content_field_name') ) : the_row();

        if( get_row_layout() == 'paragraph' ):

        	the_sub_field('text');

        elseif( get_row_layout() == 'download' ): 

        	$file = get_sub_field('file');

        endif;

    endwhile;

else :

    // no layouts found

endif;

?>
Output here:

Drag and drop a section

Leave a Comments