Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a front end post form where users can upload a file with their post that I save as an attachment using media_handle_sideload(). I need a way to add a term to that attachment so I can show a loop of all specific attachments by a user with that term.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

media handle sideload returns an attachment ID, and attachments are normal posts with the post type 'attachment'. All the same things apply, featured images parents taxonomies post meta etc albeit with a few attachment oriented functions like wp_get_attachment_image

So use wp_set_object_terms as you normally would, e.g.:

$id = media_handle_sideload(.... 
if(!is_wp_error($id)){
    wp_set_object_terms( $id, array(terms...), $taxonomy, $append );
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.