title: Display hierarchy of the terms for the current post (Wordpress)
body: <p>I am trying to display a hierarchy of the terms for the current post in Wordpress like this :</p>
  
  <pre><code>    $terms = get_the_terms( get_the_ID(), 'type' );
      if($terms) {
          foreach( $terms as $term ) {
              $term_parent = get_term_by("id", $term-&gt;parent, "type");
              $parent_term_link = get_term_link( $term_parent );
              if ($term-&gt;parent &gt; 0) {
                  echo '&lt;a href="'. $parent_term_link .'"&gt;'. $term_parent-&gt;name . '&lt;/a&gt; ';
              }
              // for the children now
              $children_terms = get_the_terms(get_the_ID(), 'type');
              if($children_terms) {
                  foreach ( $children_terms as $children_term ) {
                      echo '&lt;pre&gt;';
                      var_dump($children_term);
                      echo '&lt;/pre&gt;';
                      if ( $children_term-&gt;parent === $term_parent-&gt;term_id ) {
                          echo $term-&gt;name;
                          break;
                      }
                  }
              }
  
          }
      }
  </code></pre>
  
  <p>I quite dit it but I got this error in return :</p>
  
  <pre><code>Notice: Trying to get property of non-object in /web/wp-content/themes/make-child/partials/entry-meta-post-footer.php on line 25
  
  Notice: Trying to get property of non-object in /web/wp-content/themes/make-child/partials/entry-meta-post-footer.php on line 25
  </code></pre>
  
  <p>for the line 25 :</p>
  
  <pre><code>if ( $children_term-&gt;parent === $term_parent-&gt;term_id ) {
  </code></pre>
  
  <p>How can I avoid this error message (even if it returns the good result) ?</p>
  
  <p>Here's what the var_dump is returning :</p>
  
  <pre><code>object(WP_Term)#3205 (11) {
    ["term_id"]=&gt;
    int(39)
    ["name"]=&gt;
    string(3) "#10"
    ["slug"]=&gt;
    string(2) "10"
    ["term_group"]=&gt;
    int(0)
    ["term_taxonomy_id"]=&gt;
    int(39)
    ["taxonomy"]=&gt;
    string(4) "type"
    ["description"]=&gt;
    string(0) ""
    ["parent"]=&gt;
    int(25)
    ["count"]=&gt;
    int(2)
    ["filter"]=&gt;
    string(3) "raw"
    ["object_id"]=&gt;
    int(44)
  }
  
  (good result between)
  
  object(WP_Term)#3205 (11) {
    ["term_id"]=&gt;
    int(39)
    ["name"]=&gt;
    string(3) "#10"
    ["slug"]=&gt;
    string(2) "10"
    ["term_group"]=&gt;
    int(0)
    ["term_taxonomy_id"]=&gt;
    int(39)
    ["taxonomy"]=&gt;
    string(4) "type"
    ["description"]=&gt;
    string(0) ""
    ["parent"]=&gt;
    int(25)
    ["count"]=&gt;
    int(2)
    ["filter"]=&gt;
    string(3) "raw"
    ["object_id"]=&gt;
    int(44)
  }
  </code></pre>
  
  <p>Thanks</p>