Created
December 20, 2015 19:54
-
-
Save hirejordansmith/038aa23d078be0688a58 to your computer and use it in GitHub Desktop.
How to get ACF Repeater field values from the parent page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment