Created
October 28, 2013 03:18
-
-
Save leoken/7190969 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
* Loop through a Repeater field | |
*/ | |
if( get_field('repeater') ) | |
{ | |
while( has_sub_field('repeater') ) | |
{ | |
$variable = get_sub_field('sub_field'); | |
// do something with sub field... | |
} | |
} | |
/* | |
* Loop through a Flexible Content field | |
*/ | |
if( get_field('flexible_content') ) | |
{ | |
while( has_sub_field("flexible_content") ) | |
{ | |
if( get_row_layout() == "paragraph" ) // layout: Paragraph | |
{ | |
$variable = get_sub_field('sub_field'); | |
// do something with sub field... | |
} | |
elseif( get_row_layout() == "file" ) // layout: File | |
{ | |
$variable = get_sub_field('sub_field'); | |
// do something with sub field... | |
} | |
} | |
} | |
/* | |
* Loop through nested Repeater fields | |
*/ | |
if( get_field('parent_repeater') ): ?> | |
<?php while( has_sub_field('parent_repeater') ): ?> | |
<div> | |
<?php if( get_sub_field('child_repeater') ): ?> | |
<ul> | |
<?php while( has_sub_field('child_repeater') ): ?> | |
<li> | |
<?php | |
$variable = get_sub_field('sub_field'); | |
// do something with sub field... | |
?> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php endif; ?> | |
</div> | |
<?php endwhile; ?> | |
<?php endif; | |
/* | |
* Loop through nested Repeater fields (From another $post ID) | |
*/ | |
if( get_field('parent_repeater', 123) ): ?> | |
<?php while( has_sub_field('parent_repeater', 123) ): ?> | |
<div> | |
<?php | |
/* | |
* note: you don't need to specify the $post_id for any sub field functions | |
*/ | |
if( get_sub_field('child_repeater') ): ?> | |
<ul> | |
<?php while( has_sub_field('child_repeater') ): ?> | |
<li> | |
<?php | |
$variable = get_sub_field('sub_field'); | |
// do something with sub field... | |
?> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php endif; ?> | |
</div> | |
<?php endwhile; ?> | |
<?php endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment