Correct Way To Show Custom Taxonomy for Image Attachments on Template File

The issue is with the post_status argument of the default query generated for your taxonomy terms. If you change the status via the pre_get_posts action to inherit or any, you can get attachments to show up.

however– is this the correct way to do this- I honestly don’t know. This will show attachments to posts that are drafts, and maybe private. I haven’t tested it thoroughly so beware.

Perhaps someone else can chime in with more knowledge and info.

function wpa82573_show_tax_attachments( $query ) {
    if ( $query->is_tax('imagetags') && $query->is_main_query() ) {
        $query->set( 'post_status', 'inherit' );
    }
}
add_action( 'pre_get_posts', 'wpa82573_show_tax_attachments' );