Home › Forums › Add-ons › Repeater Field › Nested Repeaters Using Get Post Meta
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);
}
}
The topic ‘Nested Repeaters Using Get Post Meta’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.