• Resolved ashf

    (@ashf)


    Is there way to add a category to files when upload programmatically?

    like by using attachment_fields_to_save() or something?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author webbistro

    (@webbistro)

    Hi @ashf,

    Yes, please use:

    add_action( 'add_attachment', 'YOUR_PREFIX_add_attachment' );
    
    function YOUR_PREFIX_add_attachment( $attachment_ID ) {
        
        $term_id = array( 14 );  // term ID(s)
        $taxonomy = 'media_category'; // taxonomy name to assign
        
        wp_set_object_terms( $attachment_ID, $term_ids, $taxonomy, false );
    }

    Best,
    -Nadia

    Thread Starter ashf

    (@ashf)

    Thanks for quick answer!

    Where I have to add this code ?
    I need this option to.

    Thread Starter ashf

    (@ashf)

    functions.php in theme folder.
    (Child theme is recommended)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add media category when upload’ is closed to new replies.