Created
April 11, 2014 18:50
-
-
Save emaildano/10491799 to your computer and use it in GitHub Desktop.
Get the first sub-field from a flexible content field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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