Home Forums Add-ons Repeater Field How to get values from another page FIX


How to get values from another page FIX

  • Using the page ID directly in my repeater field did not work. However, if I created variable $other_page= 12; in which “12” is my page ID I am able to retrieve the field data from another page.

    The documentation in the following example appears to be wrong. Any reason why I wouldn’t be able to use the page ID directly per this example?

    <?php if(get_field('repeater_field_name', 123)): ?>
    	<?php while(has_sub_field('repeater_field_name', 123)): ?>
    		<li>sub_field_1 = <?php the_sub_field('sub_field_1'); ?>, sub_field_2 = <?php the_sub_field('sub_field_2'); ?>, etc</li>
    	<?php endwhile; ?>
    <?php endif; ?>

    I found the above code from the following How To page:
    “How to get values from another page Documentation” (the repeater example does not work for me unless I create a page ID variable):

  • Hi @negrelja

    I can’t think of any reason why you can’t use a number instead of a variable.
    Can you post the code which is causing the issue? Perhaps it is something else.


  • The following example worked for me but stopped working if I replaced the variable with the page ID value directly.

    <?php $other_page=44; ?>
    <div class="tab-pane <?php the_field('active_tab_1', $other_page); ?>" id="<?php the_field('tab_title_1', $other_page); ?>">
    	<?php if( get_field('inducteerow_loop', $other_page) ): ?>
    		<?php while( has_sub_field('inducteerow_loop', $other_page) ): ?>
                    <div>HTML Content Goes Here</div>
    <?php endwhile; ?>
    <?php endif; ?>

    Thank you for the reply.

  • Hi @negrelja

    Perhaps you did not replace all of the $other_page variables? I can see 3 in your code. Be sure to replace them all.

    That said, the variable is much smarter as you only need to define the ID once!


  • I agree that using a variable is definitely the better way to go but was perplexed by the fact that the variable worked but not the ID value as referenced in the documentation. Thank you for looking into this.

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

The topic ‘How to get values from another page FIX’ is closed to new replies.