Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Yakub Yankowski

    (@yakub-yankowski)

    Could you provide some example code for it?
    This is so urgent…

    Plugin Author webbistro

    (@webbistro)

    Hi Yakub,

    Sorry, the title is somewhat in contradiction with the description. What exactly you need: (1) to auto upload image to a specific category or (2) to allow non-admin users to upload images and assign them to categories?

    Regards,
    -Nadia

    Thread Starter Yakub Yankowski

    (@yakub-yankowski)

    Now I want to upload image not in admin panel.

    I have create media category called as “MyMedia”.
    So I want to move images that any user uploaded.

    Now I am implementing this, but some difficult.
    I have used function wp_set_object_terms, but it not works.

    Please help me.

    Plugin Author webbistro

    (@webbistro)

    Yakub,

    Since I don’t quite understand your task, the common information:

    add_action( 'add_attachment', 'your_prefix_add_attachment' );
    
    function your_prefix_add_attachment( $post_ID ) {
    
        $term_ids = array( 14 );  // ID of your "MyMedia" category to assign to the uploading media file
        $taxonomy = 'media_category'; // taxonomy name
    
        wp_set_object_terms( $post_ID, $term_ids, $taxonomy, false );
    }

    This code will add any uploaded image to media category with the ID 14.

    Hope this helps.

    -Nadia

    Thread Starter Yakub Yankowski

    (@yakub-yankowski)

    OK. It works. Many thanks.

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

The topic ‘Upload image to media category by code’ is closed to new replies.