Home › Forums › Add-ons › Repeater Field › 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)): ?> <ul> <?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; ?> </ul> <?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):
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; ?> </div>
Thank you for the reply.
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.
The topic ‘How to get values from another page FIX’ 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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.