My gallery has dozens of images. Next to each image, there should be links to the posts attached to that image. (You can see these in Media Library, under "Uploaded To").
I am able to retrieve the post's ID with
$attachment_data['uploadedTo'], but how can I get the name of that post?
$the_query = new WP_Query( array( 'post_type' => 'attachment', 'category_name' => 'photos', 'posts_per_page' => 25, )); while ( $the_query->have_posts() ) : $the_query->the_post(); $attachment_data = wp_prepare_attachment_for_js($attachment); echo '<div><div> <img src="'.wp_get_attachment_url ('medium').'"/> </div><div><a href="/?p='.$attachment_data['uploadedTo'].'"> Name of Post Goes Here</a></div>'; endwhile; wp_reset_postdata();?>