I have narrowed my issue down to this set of code:
$post_id = $posts[$j]->ID;
setup_postdata($posts[$j]);
$excerpt = get_the_excerpt();
$attachment_url = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'full' );
$url = $attachment_url['0'];
$image = aq_resize($url, $thumb_width, $thumb_height, true);
$mediaType = get_post_meta($post_id, 'tz_portfolio_type', true);
$prettyType = 0;
if ($count > $columns) {
$count = 1;
$output .= '<ul class="posts-grid row-fluid unstyled '. $custom_class .'">';
}
$output .= '<li class="'. $spans .'">';
if(has_post_thumbnail($post_id) && $mediaType == 'Image') {
$prettyType = 'prettyPhoto-'.$rand;
$output .= '<figure class="featured-thumbnail thumbnail">';
$output .= '<a href="'.$url.'" title="'.get_the_title($post_id).'" rel="' .$prettyType.'">';
$output .= '<img src="'.$image.'" alt="'.get_the_title($post_id).'" />';
$output .= '<span class="zoom-icon"></span></a></figure>';
} elseif ($mediaType != 'Video' && $mediaType != 'Audio') {
$thumbid = 0;
$thumbid = get_post_thumbnail_id($post_id);
$images = get_children( array(
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post_id,
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1
) );
if ( $images ) {
$k = 0;
//looping through the images
foreach ( $images as $attachment_id => $attachment ) {
$prettyType = "prettyPhoto-".$rand ."[gallery".$i."]";
//if( $attachment->ID == $thumbid ) continue;
$image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' ); // returns an array
$img = aq_resize( $image_attributes[0], $thumb_width, $thumb_height, true ); //resize & crop img
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
if ( $k == 0 ) {
if (has_post_thumbnail($post_id)) {
$output .= '<figure class="featured-thumbnail thumbnail">';
$output .= '<a href="'.$image_attributes[0].'" title="'.get_the_title($post_id).'" rel="' .$prettyType.'">';
$output .= '<img src="'.$image.'" alt="'.get_the_title($post_id).'" />';
} else {
$output .= '<figure class="featured-thumbnail thumbnail">';
$output .= '<a href="'.$image_attributes[0].'" title="'.get_the_title($post_id).'" rel="' .$prettyType.'">';
$output .= '<img src="'.$img.'" alt="'.get_the_title($post_id).'" />';
}
} else {
$output .= '<figure class="featured-thumbnail thumbnail" style="display:none;">';
$output .= '<a href="'.$image_attributes[0].'" title="'.get_the_title($post_id).'" rel="' .$prettyType.'">';
}
$output .= '<span class="zoom-icon"></span></a></figure>';
$k++;
}
} elseif (has_post_thumbnail($post_id)) {
$prettyType = 'prettyPhoto-'.$rand;
$output .= '<figure class="featured-thumbnail thumbnail">';
$output .= '<a href="'.$url.'" title="'.get_the_title($post_id).'" rel="' .$prettyType.'">';
$output .= '<img src="'.$image.'" alt="'.get_the_title($post_id).'" />';
$output .= '<span class="zoom-icon"></span></a></figure>';
}