I wanted to apply the same categories that exist for posts to attachments, so I wrote this code:
function wpmediacategory_init() {
register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init', 'wpmediacategory_init' );
The problem I am having now is that behaviour is not quite like with posts. There a 2 features I would like to achieve:
- When adding a new attachment, set it to “Uncategorized”
- When updating an attachment, if it has no categories selected, set it to the “Uncategorized” category.
I have been trying to think what hooks I could be using, but without much success. How could I solve this problem?
To solve the problem 1, you could hook to add_attachment and edit_attachment hook.