Support

Account

Home Forums Add-ons Repeater Field Get subfields from a repeater on one page to appear on another page – not workin

Solved

Get subfields from a repeater on one page to appear on another page – not workin

  • I’m trying to grab the values of a repeater field from an English page, and display them on a Chinese page (I’m using Polylang, but that shouldn’t matter). When i dump any of the variables, they aren’t grabbing the English values from the English page (22283) but grabbing the Chinese instead. Doesn’t work when I hardcode the page ID ($regions2 = get_sub_field('regions_list', 22283);) in either. Any ideas?

        	<div class="row">
    		    <?php
    
    		    $engID = 22283;
    		    $regions2 = get_sub_field('regions_list', $engID);
    
    			foreach ($regions2 as $region2) {
    
    				global $i;
    				$i++;
    						
    					        echo  "<div id='tab-{$i}'>
    					        	   <ul class='payment-countries'>";
    
    					        	    $region_loop = strtolower(str_replace(' ', '_', $region2['region_entry']));
    
    					        	    var_dump($region_loop);
    
    									    if(have_rows($region_loop)) : while ( have_rows($region_loop) ) : the_row(); ?>
    									    
    							       				<div class="col col-4 tab-card">
    													<div class="icon-container">
    														<span class="icon icon-flags icon--<?php the_sub_field('flag'); ?>"></span>
    													</div>
    													<h3><?php esc_html(the_sub_field('country')); ?></h3>
    													<span class="boldText"><?php echo $most_popular_payment_methods_text; ?></span>
    													<ol>
    														<?php if(have_rows('list')) : while(have_rows('list')) : the_row(); ?>
    															<li><?php esc_html(the_sub_field('method')); ?></li>
    														<?php endwhile; endif; ?>
    													</ol>
    												</div>
    
    									    <?php 
    									    endwhile; endif;
    
    					        echo    '</ul>';
    						echo '</div>';
    			}
    
    			echo '</div>';
    			?>
    		</div><!--row-->
  • Hi @websitewalrus

    The get_sub_field() does not accept a post_id parameter, please assign this to the have_rows() like so:

    // check if the repeater field has rows of data
    if( have_rows('repeater_field_name','22283') ):
    
     	// loop through the rows of data
        while ( have_rows('repeater_field_name','22283') ) : the_row();
    
            $regions2 = get_sub_field('regions_list');
    
        endwhile;
    
    else :
    
        // no rows found
    
    endif;
  • My setup is a bit more complicated than I explained – but knowing that the_sub_field() doesn’t accept an ID parameter solved my issue!

    Rather than using the ‘regions_list’ as a sub field, I added it to an option page and changed the variable for regions2 like this:$regions2 = get_field('regions_list', 'option', $engID);

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

The topic ‘Get subfields from a repeater on one page to appear on another page – not workin’ is closed to new replies.