'ct_gallery', 'posts_per_page' => -1, 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'ct_gallery_category', 'field' => 'term_id', 'terms' => $selectedGalleryCategoryID, ), ), ); $gallery_query = new WP_Query( $args ); $images = array(); $count = 0; $rand = wp_generate_password( 12, false, false ); $div_id = 'image_grid_1_' . $rand; ob_start(); if( $gallery_query->have_posts() ): while( $gallery_query->have_posts() ): $gallery_query->the_post(); global $post; $post_thumbnail_id = get_post_thumbnail_id( $post->ID ); $image_arr = wp_get_attachment_image_src( $post_thumbnail_id, 'large' ); $images[$count]['src'] = !empty( $image_arr[0] ) ? esc_url( $image_arr[0] ) : ''; $images[$count]['alt'] = get_the_title(); $images[$count]['title'] = get_the_title(); $images[$count]['caption'] = get_the_title(); $images[$count]['thumbnail'] = !empty( $image_arr[0] ) ? esc_url( $image_arr[0] ) : ''; $count++; endwhile; if( !empty( $images ) ){ echo '