Here is a working example of retrieving the values from an Advanced Custom Fields (ACF) repeater field and outputting the data on another page.
In this case, I was outputting the data on all child pages of a parent by retrieving the page id of the parent.
| <?php | |
| // Get the id of the parent page | |
| $pid = wp_get_post_parent_id( get_the_ID() ); | |
| // Use $pid in get_post_meta() to get the repeater field (will return number of rows) | |
| $page_more_products_child = get_post_meta($pid, 'page_more_products', true); | |
| if( $page_more_products_child ) { // GET ACF Repeater field data from another page | |
| for ($i=0; $i<$page_more_products_child; $i++) { | |
| $graphic_id_meta_key = 'page_more_products_'.$i.'_pmp_graphic'; | |
| $subtitle_meta_key = 'page_more_products_'.$i.'_pmp_subtitle'; | |
| $description_meta_key = 'page_more_products_'.$i.'_pmp_description'; | |
| $link_meta_key = 'page_more_products_'.$i.'_pmp_link'; | |
| $graphic_id = get_post_meta($pid, $graphic_id_meta_key, true); | |
| $graphic = wp_get_attachment_image($graphic_id, 'more-products'); | |
| $subtitle = get_post_meta($pid, $subtitle_meta_key, true); | |
| $description = get_post_meta($pid, $description_meta_key, true); | |
| $link = get_post_meta($pid, $link_meta_key, true); | |
| ?> | |
| <div class="product"> | |
| <a href="<?php echo $link; ?>"> | |
| <div class="image-wrap"> | |
| <?php echo $graphic; ?> | |
| </div> | |
| <div class="content-wrap"> | |
| <h3><?php echo $subtitle; ?></h3> | |
| <p><?php echo wp_trim_words($description, 12, ''); ?></p> | |
| </div> | |
| </a> | |
| </div> | |
| <?php } | |
| } |
Here is a great resource from the ACF site for getting and outputting field data from another post:
http://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/