1 2 3 4 | function wptp_add_categories_to_attachments() { register_taxonomy_for_object_type( 'category' , 'attachment' ); } add_action( 'init' , 'wptp_add_categories_to_attachments' ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $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' />" ; }} |
1 2 3 4 5 | // 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' ); |