title: WordPress: Get top level taxonomy by term ID
body: <p>I've an ID of a custom taxonomy. Now I try to get the top level taxonomy of that ID.</p>
  <p>For example, this is my taxonomy tree:</p>
  <ul>
  <li>Cars (ID: 1)
  <ul>
  <li>Mercedes (ID: 2)
  <ul>
  <li>S-Class (ID: 3)</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>I try to get the ID from the first level (ID: 1) based on the ID 3.</p>
  <p>I found a lot of examples but they don't work with only one given integer/ID.</p>
  <p>For example this one:</p>
  <pre><code>function get_term_top_most_parent( $term_id, $taxonomy ) {
      $parent  = get_term_by( 'id', $term_id, $taxonomy );
      while ( $parent-&gt;parent != 0 ){
          $parent  = get_term_by( 'id', $parent-&gt;parent, $taxonomy );
      }
      return $parent;
  }
  </code></pre>
  <p>I changed <code>$term_id</code> with <code>3</code> but it doesnt do anything.</p>