setting a custom taxonomy term to file uploaded via advanced image field?

Support General setting a custom taxonomy term to file uploaded via advanced image field?Resolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #22935
    AshAsh
    Participant

    I created a custom taxonomy to organize Media Library.
    The code below works for built-in feature of WP such as featured image or Media Library uploader, but does not work with Metabox field.
    I'd like to set a default term to files uploaded from cpt post.

    function set_media_category($post_ID){
    if(!empty($_POST['post_id']) && get_post_type($_POST['post_id'])=='cpt'){ wp_set_object_terms($post_ID,102,'media_category'); }
    else{ wp_set_object_terms($post_ID,103,'media_category'); }
    }
    add_action('add_attachment','set_media_category',30,1);
    add_action('edit_attachment', 'set_media_category',30,1);

    #22946
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The code works as well with the Meta Box fields, see my screen record https://share.getcloudapp.com/OAuWKRX6.

    But you need to use some fields which upload the media via WordPress Media Library popup like the featured image such as image_advanced, single_image, file_advanced.

    https://docs.metabox.io/fields/image-advanced/
    https://docs.metabox.io/fields/single-image/
    https://docs.metabox.io/fields/file-advanced/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.