Last updated Apr 4, 2024


This function is deprecated. Please use the have_rows() function instead.

This function is used within a while-loop to loop through each row of a Flexible Content field.

Unlike have_rows(), this function will take a step through the available rows each time it is called, causing undesired results when also used within an if-statment.


the_flexible_field( $field_name, $post_id );
  • $field_name (string) (Required) The name of the Flexible Content field to be retrieved. e.g. ‘content’
  • $post_id (mixed) (Optional) The post ID where the value is saved. Defaults to the current post.


(bool) True if a row exists.

Change Log

  • Deprecated in version 3.3.4
  • Added in version 3.1.0



This example demonstrates how to loop through a Flexible Content field called “content” and display various layouts.

<?php while( the_flexible_field("content") ): ?>
    <?php if( get_row_layout() == "paragraph" ): ?>
            <?php the_sub_field("content"); ?>
    <?php elseif( get_row_layout() == "file" ): ?>
            <a href="<?php the_sub_field("file"); ?>" ><?php the_sub_field("name"); ?></a>
    <?php elseif( get_row_layout() == "featured_posts" ): ?>
            <h2><?php the_sub_field("title"); ?></h2>
            <?php the_sub_field("content"); ?>
            <?php if( get_sub_field("posts") ): ?>
                <?php foreach( get_sub_field("posts") as $p ): ?>
                    <li><a href="<?php echo get_permalink($p->ID); ?>"><?php echo get_the_title($p->ID); ?></a></li>
                <?php endforeach; ?>
            <?php endif; ?>
    <?php endif; ?>
<?php endwhile; ?>