Skip to content

Instantly share code, notes, and snippets.

@emaildano
Created April 11, 2014 18:50
Show Gist options
  • Save emaildano/10491799 to your computer and use it in GitHub Desktop.
Save emaildano/10491799 to your computer and use it in GitHub Desktop.
Get the first sub-field from a flexible content field.
<?php
// If the page has Flexible Content:
if(get_field('flexible_main_content')) :
$rows = get_field('flexible_main_content');
// Get the first instance of the Body Copy field
foreach( array_slice($rows, 0, 1) as $row ) {
$excerpt = $row['body_copy'];
echo '<p>' . trunc($excerpt, 15) . '</p>';
}
// Otherwise get the content
else: ?>
<?php the_content(); ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment