So I am trying to list out all the tags created for images uploaded within my custom post type only. I added in a snippet of code to my themes functions.php file to enable media categories and tags:
function wptp_add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
I am using the following code within my template file to generate a list of tags from my custom post type... but hopefully some fresh eyes can show me what I need to do to it to just show the tags I have generated on my images that are uploaded within this custom post type:
<ul class="work_tags_nav">
<li class="active"><a class="all">all.</a></li>
<?php
query_posts(array( 'post_type'=> 'work', 'taxonomy' => 'type', 'term' => 'case-study' ));
if ( have_posts() ) : while ( have_posts() ) : the_post();
$custom_post_tags = get_the_tags();
if ( $custom_post_tags ) {
foreach( $custom_post_tags as $tag ) {
$tags_arr[] = $tag -> name;
}
}
endwhile; endif;
if( $tags_arr ) {
$uniq_tags_arr = array_unique( $tags_arr );
foreach( $uniq_tags_arr as $tag ) {
// LIST ALL THE TAGS FOR DESIRED POST TYPE
$sanitizeTag = sanitize_title($tag);
$tag_link = get_terms('name', $tag, 'post_tag');
$tag_class = preg_replace('/[^A-Za-z0-9-]+/', '_', html_entity_decode($tag)); // This strips our sepcial characers and spaces, then replaces them with an underscore
//echo '<li><a class="'.$tag.'" href="'. get_tag_link($tag_link->term_id).'">' .$tag. '.</a></li>';
echo '<li><a class="'.$tag_class.'">' .$tag. '.</a></li>';
}
}
?>
</ul>
Any help would be appreciated.. thanks!