Title: Programmatically assign category
Last modified: June 19, 2018

---

# Programmatically assign category

 *  Resolved [@PhilipHoy](https://wordpress.org/support/users/venomphil/)
 * (@venomphil)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/programmatically-assign-category/)
 * Hi Enhanced media library
 * I’d like to use your plugin to sort out my media library – currently users submit
   documents via a front end form and they are sorted in the standard WordPress 
   media library (its a mess!). If there a way to programmatically assign a category
   to this document?
 * If so how?
 * Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [webbistro](https://wordpress.org/support/users/webbistro/)
 * (@webbistro)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/programmatically-assign-category/#post-10415481)
 * Hi [@venomphil](https://wordpress.org/support/users/venomphil/),
 * Enhanced Media Library registers a taxonomy Media Categories and you can add 
   any other custom taxonomy with its UI. It uses `register_taxionomy` core function.
   So, you can use `wp_set_object_terms` to set a specific taxonomy term(s) to an
   attachment.
 * Best,
    -Nadia
 *  Thread Starter [@PhilipHoy](https://wordpress.org/support/users/venomphil/)
 * (@venomphil)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/programmatically-assign-category/#post-10417663)
 * Thanks for the feedback, programatically how would you set a term with your plugin?
 * Guessing something like
 * wp_set_object_terms(image ID, category name, ‘media_category’);
    -  This reply was modified 7 years, 9 months ago by [@PhilipHoy](https://wordpress.org/support/users/venomphil/).
    -  This reply was modified 7 years, 9 months ago by [@PhilipHoy](https://wordpress.org/support/users/venomphil/).
 *  Plugin Author [webbistro](https://wordpress.org/support/users/webbistro/)
 * (@webbistro)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/programmatically-assign-category/#post-10436008)
 * Hi [@venomphil](https://wordpress.org/support/users/venomphil/),
 * The example:
 *     ```
           $term_ids = array( 14, 19 );  // media category IDs
           $taxonomy = 'media_category'; // or any other media taxonomy name
   
           wp_set_object_terms( $attachment_ID, $term_ids, $taxonomy, false );
       ```
   
 * You can read more about `wp_set_object_terms` here [https://codex.wordpress.org/Function_Reference/wp_set_object_terms](https://codex.wordpress.org/Function_Reference/wp_set_object_terms)
 * Best,
    -Nadia

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Programmatically assign category’ is closed to new replies.

 * ![](https://ps.w.org/enhanced-media-library/assets/icon-256x256.png?rev=980107)
 * [Enhanced Media Library](https://wordpress.org/plugins/enhanced-media-library/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/enhanced-media-library/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/enhanced-media-library/)
 * [Active Topics](https://wordpress.org/support/plugin/enhanced-media-library/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/enhanced-media-library/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/enhanced-media-library/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * 3 replies
 * 2 participants
 * Last reply from: [webbistro](https://wordpress.org/support/users/webbistro/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/programmatically-assign-category/#post-10436008)
 * Status: resolved