Home › Forums › General Issues › List all gallery items of child pages › Reply To: List all gallery items of child pages
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
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.