This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists.


  • Deprecated in v3.3.4 – please replace with has_sub_field
  • Added in v3.1.0

This function is used in a “while loop” to loop through each row of  a flexible content field.  This function requires the flexible content field (activation code required).

This function will return either: the current row (continue loop) or false (end of loop). Within the “while loop”, you can use these functions:


<?php the_flexible_field($field_name, $post_id); ?>
  • $field_name: the name of the flexible content field to be retrieved. eg “page_content” (required)
  • $post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc



*  Loop through a Flexible Content field and display it's content with different views for different layouts

while(the_flexible_field("content")): ?>

	<?php if(get_row_layout() == "paragraph"): // layout: Content ?>

			<?php the_sub_field("content"); ?>

	<?php elseif(get_row_layout() == "file"): // layout: File ?>

			<a href="<?php the_sub_field("file"); ?>" ><?php the_sub_field("name"); ?></a>

	<?php elseif(get_row_layout() == "featured_posts"): // 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; ?>

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.