Categories for Attachments

Categories

function wptp_add_categories_to_attachments() {
    register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'wptp_add_categories_to_attachments' );

To Apply It Use “get_posts”

$call_args = array(
    'post_type'        => 'attachment',
    'cat'              => 5, 
    'posts_per_page'   => -1
);

$attachments = get_posts($call_args);

if (!empty($attachments)) { foreach($attachments as $attachment) { 
    
	$src = $attachment->guid;
	echo "<img src='$src' />"; 

}}

Tags

// apply tags to attachments
function wptp_add_tags_to_attachments() {
    register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
Comments