<?php
$images =[];
$imagesArrays = [];
//The Loop
$loop = new WP_Query( array( 'post_type' => 'gallery',
'posts_per_page' => 100 )
);
while ( $loop->have_posts() ) : $loop->the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
/* Loop through all the image and output them one by one */
foreach( $gallery['src'] as $src ) : ?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
<?php
//Creates an Array Gallery Images from the Post
//Array (
// [0] => http://velnikolic.com/gallery/wp-content/uploads/2017/04/file4741298583098-1-1024x653.jpg
// [1] => http://velnikolic.com/gallery/wp-content/uploads/2017/04/file9221293737060-1024x683.jpg
// [2] => http://velnikolic.com/gallery/wp-content/uploads/2017/04/file4741298583098-1024x653.jpg
// )
$images = $gallery['src'];
endforeach;
endif;
//Push $images arrays into one array
$imagesArray = array($images);
print_r($imagesArray);
endwhile; wp_reset_query(); ?>
I would like to push the images array into a list of arrays accessible by a key. $imagesArray = array($images); doesn't append the $images array, only overwrites it.