Hey,
I’m currently building a theme using ACF. I’m using get_post_meta throughout rather than using get_field and I’ve got all working, however, I’ve run into an issue using a nested repeater, I can seem to get the nested fields to display.
Here’s the code I’m working with:
<?php if ( $badges ) {
for ( $i = 0; $i < $badges; $i++ ) {
$badges_title = get_post_meta( $post->ID, 'badges_' . $i . '_badges_title', true );
$badges_description = get_post_meta( $post->ID, 'badges_' . $i . '_badges_description', true );
?>
<!-- This repeater is displaying no problem -->
<?php if ( $badges_title && $badges_description ) { ?>
<h3><?php echo wp_kses_post( $badges_title ); ?></h3>
<p><?php echo wp_kses_post( $badges_description ); ?></p>
<?php } ?>
<!-- This nested repeater is not displaying -->
<?php if ( $badge ) {
for ( $i = 0; $i < $badge; $i++ ) {
$badge_title = get_post_meta( $post->ID, 'badge_' . $i . '_badge_title', true );
$badge_description = get_post_meta( $post->ID, 'badge_' . $i . '_badge_description', true );
?>
<?php if ( $badge_title && $badge_description ) { ?>
<h3><?php echo wp_kses_post( $badge_title ); ?></h3>
<p><?php echo wp_kses_post( $badge_description ); ?></p>
<?php } ?>
<?php }
} ?>
<?php }
} ?>
Any ideas?
Thanks in advanced.
Paul
I can’t tell by looking at your code what you’re trying to do, I don’t see any “nesting”. Here is basic code to get sub fields of a nested repeater.
$repeater = 'repeater_name';
$repeater_count = intval(get_post_meta($post_id, $repeater, true));
$nested_repeater = 'nested_repeater_name';
for ($i=0; $i<$repeater_count; $i++) {
$nested_count = intval(get_post_meta($post_id, $repeater.'_'.$i.'_'.$nested_repeater, true);
for ($j=0; $j<$nested_count; $j++) {
// get value of field in nested repeater
$value = get_post_meta($post_id, $repeater.'_'.$i.'_'.$nested_repeater.'_'.$j.'_sub_field_name', true);
}
}