Here’s the fix. All the attachment info is now being called inside the php using wp_prepare_attachment_for_js
and the info will load for each image in the loop, to display in the photo gallery. It works now.
<?php
$the_query = new WP_Query(array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'category_name' => 'arch'
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<?php $attachment_data = wp_prepare_attachment_for_js( $attachment->ID );
echo '<figure class="gallery-photo" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" data-groups=". esc_attr("["all"]').'>';
echo'<a class="photo-link" href="'.$attachment_data['url'].'" itemprop="contentUrl" data-size="'.$attachment_data['width'].'x'.$attachment_data['height'].'">';
echo'<img src="'.wp_get_attachment_url ('medium').'" itemprop="thumbnail"/>';
echo'<figcaption itemprop="caption description"'.$attachment_data['description'].'"></figcaption>';
echo'<div class="photo-title"><h2>'.$attachment_data['title'].'</h2></div></a>
</figure>';?>
<?php
endwhile;
wp_reset_postdata();
?>
For functions.php:
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}