get_the_terms error

Question

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)
         break;

} //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.

0
, , TKEz 7 years 2016-09-07T16:15:41-05:00 0 Answers 75 views 0

Leave an answer

Browse
Browse