Adding taxonomy terms based on custom field

You should be able to just the following:

Just a couple of things to note:

  • By using get_term_by() instead of term_exists(), you hit the term cache instead of the database for every retrieval of the term object.
/**
 * Set terms for the given post type based on a meta value.
 */
function wpdocs_set_terms_for_post_types() {
    $posts = get_posts( array(
        'posts_per_page' => -1,
        'post_type'      => 'uc-collections',
    ) );

    if ( ! empty( $posts ) ) {
        foreach ( $posts as $post ) {
            if ( $meta = get_post_meta( $post->ID, 'input_type', true ) {
                if ( is_string( $meta ) && $term = get_term_by( 'slug', strtolower( $meta ) ) ) {
                    wp_set_post_terms( $post->ID, $term->slug, 'input' );
                }
            }
        }
    }
}
wpdocs_set_terms_for_post_types();