Support

Account

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