How can I add the “Use as featured image” to a custom metabox?

even if you had included the all of the needed files you will still have to create your some extra hidden fields like _nonce to pass the

check_ajax_referer( "set_post_thumbnail-$post_ID" );

also you would need to create an action hidden field to identify the case of Ajax call with the value : "set-post-thumbnail"

You are better of creating your own Ajax call
and simply use in your callback function:

    set_post_thumbnail( $post, $thumbnail_id );
//or
    update_post_meta( $post->ID, '_thumbnail_id', $attachment_id );

and to unset use

delete_post_meta( $post_ID, '_thumbnail_id' );

Leave a Comment