loading images from custom taxonomy into fancybox 2



I’ve been going nuts trying to work this out, so I hope someone can point me in the right direction. I posted on multiple sites with no answers. I’m not a programmer so I don’t understand enough about how the PHP works. Ideally this would be a function I could call with arguments so it was all dynamic, but for now I just want to get it working.

I have a custom taxonomy in my functions file called “genre” and am using that to organize images in my media library so I can load them as galleries using fancybox 2. The problem is that all the stuff I can find online is pulling attachment images from posts, not straight from the media library based on custom taxonomy.

On the page I setup to display galleries, I’m using multiple WP_Query to check if the specific genres have images and wp_reset_postdata(); so multiple loops work. If they do have images, then I generate a with various HTML with info and an invisible, absolute tag that covers the entire . The loads up fine. When clicked, I want the anchor to launch fancybox and load up all the images (with thumbnails preferably) with some info about the active large image.

I can get it to work with 1 image (haven’t tried thumbnails yet), but any type of array I try to make doesn’t work, or it outputs 20 repeats of each image in the array and fancybox is blank, or breaks the rest of the page.

The closest thing I found was loading up thumbnails in an invisible

that had the same data group for fancybox, however, this code was again assuming that the images were attached to a post, so I can’t use it.

My guess is I will have to use that invisible

method somehow, or I will have to generate an array properly with PHP, then pass that to javascript using wp_prepare_attachment_for_js.

I’m not using wp_prepare_attachment_for_js yet, but when I generate the array it’s messed up. Wether it’s inside or outside of the while loop it’s still repeating entries—I have 2 images in this taxonomy and the array is duplicating each one over 20 times. The print_r is there for testing the array.

Here’s an example of the WP_Query and graphic-design genre.

$gd_query = new WP_Query( array(
‘post_type’ => ‘attachment’,
‘post_mime_type’ => ‘image’,
‘posts_per_page’ => -1,
‘order’ => ‘DESC’,
‘post_status’ => ‘any’,
‘tax_query’ => array(
‘taxonomy’ => ‘genre’,
‘field’ => ‘slug’,
‘terms’ => ‘graphic-design’
) );

if ( $gd_query->have_posts() ) {
while ( $gd_query->have_posts() ) {

	$src = wp_get_attachment_image_src($images_query->ID, 'full' );
	$url = $src['0'];
	$post_num = $gd_query->found_posts;
	$gd_images = array();
foreach($gd_query as $image){
	$gd_images[] = wp_prepare_attachment_for_js( $image->ID, 'full' );


graphic design


<?php echo term_description('13', 'genre')?>

<?php echo $post_num ?> images

  <?php print_r($gd_images); ?> <?php } else { // no attachments found } wp_reset_postdata(); ?>[/php]

The above code work fine for loading up the first image, but I’m not sure how to proceed to get all images and pass that to fancybox 2. I haven’t included the various other methods as they were dead-ends.

I’ve been at this for days and am at the point of murdering my computer, and would really appreciate some help resolving this. I’m just not sure how to approach this and can’t find any info anywhere.