get_the_terms error

I ended up using the wp_get_object_terms() function instead of get_the_terms(). The get_the_terms() function attempts to cache the terms where wp_get_object_terms() does not.

The fixed code to get the hero images CPT’s ID is:

$hero_image_id = ( $assigned_hero_images = wp_get_object_terms( $post_parent, 'hero_images' ) ) && ( $hero_image = array_shift( $assigned_hero_images ) ) && isset( $hero_image->term_id ) ? $hero_image->term_id : NULL;