2

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.

1 Answer 1

3

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 );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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