Hello,
Is there a way to list all the gallery items from child pages on a parent page?
I’ve gotten somewhere with it but not very far. Found this example of listing child content on the parent page from the codex: https://codex.wordpress.org/Function_Reference/get_pages#Displaying_Child_pages_of_the_current_page_in_post_format
and looking at these articles on ACF: http://www.advancedcustomfields.com/resources/filters/acfload_field/ & http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page/
Am I on the right track? How would I nest the foreach loops?
Do you want to list them separately on the same page or as one big array?
This example should work to put them all in the same array which you can then use as a regular gallery array in a foreach loop to display each image!
$args = array (
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID
);
$children = new WP_Query($args);
$gallery_array = array();
if($children->have_posts()){
while($children->have_posts()){
$children->the_post();
$childGallery = get_field('galleryfield');
if($childGallery){
$gallery_array = array_merge($childGallery, $gallery_array);
}
}
wp_reset_postdata();
}
print_r($gallery_array); //This now contains all the gallery items from the childpages, provided there are any childpages and they have galleries