[Solved] get_the_terms error

TKEz Asks: get_the_terms error
I’m using the CPT-onomies plugin to make a CPT into a taxonomy. I have a hero image CPT (created with CPT-onomies) and the hero images post type is attached to the page post type. This allows me to select a hero image post that will be a term of a page post. All of this is working fine. When I visit the page with the hero image as a taxonomy the hero image appears as desired.

What I’m trying to accomplish is that if I’m on a page whose ancestor has a hero image attached, I want the page to show the hero image attached to the parent. Below is my code. I get an array of ancestors and iterate through the array. The image shows up as desired but above the image this error appears:

Notice: Undefined property: stdClass::$data in .../wp-includes/category-template.php on line 1176

//Get the current Post ID
$current_post_id = get_the_id();

//Get the current Post's ancestor's ID's
$current_post_parents = get_ancestors($current_post_id, 'page');

foreach ( $current_post_parents as $post_parent ) {

      //If a hero image ID is associated with the current post being viewed (or a parent post of the current post) assign that hero image ID value to $hero_image_id
      $hero_image_id = isset( $post_parent ) && ( $assigned_hero_images = get_the_terms( $post_parent, 'hero_images' ) ) && is_array( $assigned_hero_images ) && ( $hero_image = array_shift( $assigned_hero_images ) ) && isset( $hero_image->term_id ) ? $hero_image->term_id : NULL;

      if ($hero_image_id)

} //Code follows that displays the image based on the $hero_image_id

It’s the get_the_terms() function that’s throwing the error. Line 1176 of the category-template.php file is $to_cache[ $key ] = $term->data;

To be clear, the notice only appears when I’m visiting a child page whose ancestor has a hero image attached. If I’m visiting the page on which the hero image is attached or visiting a page with no hero image attached on the page or any ancestor page then no error appears.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.