Home Forums Add-ons Repeater Field Show ACF values from nested repeater on another page template


Show ACF values from nested repeater on another page template

  • Hi there,

    I’m sure this has been done before, but I can’t quite figure out how. Basically, I’ve built a careers page/feed with ACF, and would like to loop through the nested repeater fields values on the home page. Kind of like how’d you’d loop through blog posts or custom post types. I’ve tried based on the following, but it’s not firing for me:

    Here’s the code from the page template I want to collect the field values from:

    					<?php if( have_rows('listings_block') ): ?>
    					    <?php while ( have_rows('listings_block') ) : the_row();
    							// vars
    							$type = get_sub_field('section_type');
    							$title = get_sub_field('section_title');
    							$intro = get_sub_field('section_intro');						
    						<section class="listings-section">
    							<div class="container">
    								<div class="section-header">
    									<h2 class="section-title"><?php echo $title; ?></h2>
    									<p class="text-center"><?php echo $intro; ?></p>
    								<?php if( have_rows('listings_row') ): ?>
    								    <?php while ( have_rows('listings_row') ) : the_row(); 
    										// vars
    										$title = get_sub_field('title');
    										$link = get_sub_field('link');
    										$name = get_sub_field('organisation_name');
    										$date = get_sub_field('close_date');
    									<?php if($type == "career") : ?>
    									<div class="listings-row listing-job">
    									<?php elseif($type == "study") : ?>
    									<div class="listings-row listing-study">
    									<?php else: ?>
    									<div class="listings-row">
    									<?php endif; ?>
    										<div class="card container">
    											<div class="card-body row align-items-top">
    												<div class="col-lg-10">
    													<h3><a href="<?php echo $link; ?>"><?php echo $title; ?></a></h3>
    													<span class="employer-name"><?php echo $name; ?></span>
    													<?php if( $date ): ?>
    													<span class="closing-date">Applications Close: <?php echo $date; ?></span>
    													<?php endif; ?>
    												<div class="col-lg-2">
    													<a href="<?php echo $link; ?>" class="btn btn-block btn-info">Apply</a>
    									<?php endwhile; ?>
    								<?php endif; // End Listings Row ?>
    					    <?php endwhile; // End Listings Section?>
    					<?php endif; ?>

    I’m trying to return a feed containing the nested repeater ACF values inside of the listings_row block. Has anyone done anything similar? It’d also be cool if I could pull in the repeater values based on the post/page slug, but it’s fine if not possible. Just getting the values showing on the other page would be a cracking start.

    Thanks for your help!

  • Hello there!
    Have you tried someting like:
    $var = get_sub_field('MY_SUB_FIELD_SLUG', XXX);
    Where XXX is the ID of the Careers page?

  • Hey mate, thanks for your help!

    I’ve tried, but still no luck in returning any values. I’ve tried both of these variations:

    <?php while( have_rows('listings_row', 28)): the_row(); ?>
        <pre><?php the_sub_field('title', 28); ?></pre>
    <?php endwhile; ?>
    <?php while( have_rows('listings_row', 28)): the_row(); ?>
        <?php $some_var = get_sub_field('title', 28); ?>
        <pre><?php echo $some_var; ?></pre>
    <?php endwhile; ?>

    Just to be clear, I’m attempting to get the values within the nested repeater. Any ideas? I’m scratching my head with this one :\

  • Ok, so I’ve managed to get the values appearing with the following!

    <?php while ( have_rows('listings_block', 28) ) : the_row(); ?>
    	<?php while( have_rows('listings_row', 28)): the_row(); ?>
    		<pre><?php the_sub_field('title'); ?></pre>
    	<?php endwhile; ?>
    <?php endwhile; ?>

    It returns the first value within the nested repeater, but it doesn’t loop through the nested rows for some reason. Any ideas as to how I could get the nested repeater looping through all of the row values?

  • Ignore the above. I had tired eyes and didn’t see the rest of the output on the page. The nested repeater loop works!

  • Hey markymark, glad that you got your problem solved. I’m having a similar issue that maybe you can help with.

    So I’ve created a Repeater File Upload with ACF so the admin can upload multiple files to a page.

    My repeater is named “downloads”. My secondary field is called “files”.

    Here is the code I’m using to display the files on my page.

    if( have_rows('downloads') ):
    			    while( have_rows('downloads') ) : the_row();
    			        $value = get_sub_field('files'); ?>
    			        <pre><?php echo $value[3]; ?><br><?php
    			        print_r(array_values($value)); ?></pre>
    			    <?php endwhile;

    the line print_r(array_values($value)); prints the entire array for each file.

    the line echo $value[3] is supposed to echo the name of the file but I get nothing.

    Any ideas or suggestions would be helpful.


  • Nevermind, I figured it out. I was trying to access the array using the wrong key value.

    Be well.

  • Nice one mate, glad you got it sorted!

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Show ACF values from nested repeater on another page template’ is closed to new replies.