I registered a custom taxonomy for ATTACHMENTS. Everything is fine on the admin side : I can tag medias with my custom taxonomy's categories, they show up with my images, etc.
I then build a template file for an Album page which filters images that have been tagged with my custom taxo's categories (grouped by categories).
Here's a sample of my code for this page :
$post_type = 'attachment';
$tax = 'albums';
$tax_terms = get_terms($tax,array('orderby' => 'id', 'order' => 'DESC') );
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
'albums' => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$terme = $tax_term->slug;
$lien_album = 'http://www.example-site.com/wp/section/albums-photo/album-individuel/?album='.$terme;
echo '<a href="'.$lien_album.'"><h3 style="margin-bottom:-8px;">'.$tax_term->name.'</h3></a><br/>';
while ($my_query->have_posts()) : $my_query->the_post();
$image_id = get_the_ID();
$image_adresse = wp_get_attachment_image_src( $image_id, 'medium');
?>
<div class="vignettes">
<img src="<?php echo $image_adresse[0]; ?>" class="vignette" alt="<?php the_title_attribute(); ?>" />
</div>
<?php
endwhile;
}
wp_reset_query();
?>
<a class="bouton-albums" href="<?php echo $lien_album; ?>">Voir les photos de cet album</a>
<p style="clear:both;"> </p>
<?php
}
}
I noticed that only images that were used in an actual page (or post) showed up in my template page.
After analysing the Codex's register_taxonomy function, I read about an argument called 'update_count_callback' and that it should use the value '_update_generic_term_count' when using a custom taxo for something other than posts. I then added it in my register_taxonomy function arguments as follow:
'update_count_callback' => '_update_generic_term_count',
Unfortunately, that doesn't seem to work. Or maybe this argument has nothing to do with what I'm trying to achieve?
I don't want each of my Albums' images to be in a page or post. I simply want to be able to add some images in the media library, tag them with my custom taxo and make them show up in my Album page (which uses my special template).
I hope someone will be able to tell me where I'm wrong or how to get what I want!