title: Get all parent taxonomies of a WordPress post type
body: <p>My question is <a href="https://stackoverflow.com/questions/15361695/show-parent-taxonomy-in-custom-post-type">similar to this</a> and used the technique myself but don't know where do  I go wrong, so let's look at the code.</p>
  
  <p>Purpose: To get a list of all parent taxonomies in an option set for a select field</p>
  
  <pre><code>&lt;option value="parent-cat-1"&gt;Parent Category 1&lt;/option&gt;
  &lt;option value="parent-cat-2"&gt;Parent Category 2&lt;/option&gt;
  &lt;option value="parent-cat-3"&gt;Parent Category 3&lt;/option&gt;
  </code></pre>
  
  <p>Here's the PHP code:</p>
  
  <pre><code>      $taxonomy_names = get_object_taxonomies( $atts['post_type']);
  
       $args = array('post_type' =&gt; $atts['post_type']);
         query_posts($args); 
  foreach ($taxonomy_names as $taxonomy_name) {
             if ( have_posts() ) : while ( have_posts() ) : the_post();
         $terms     = get_the_terms( $post-&gt;ID, $taxonomy_name );
  
          foreach( $terms as $term ) {
              $parent_term = get_term( $term-&gt;parent, $taxonomy_name );
              $term_list  .= $parent_term-&gt;name . ', ' ;
  
              }  
             var_dump($terms);
                 endwhile; endif; wp_reset_query();
                 echo $term_list;
  }
  </code></pre>
  
  <p><code>var_dump($terms);</code> shows <code>string(2) ", " string(4) ", , " string(18) ", , Category 1, , "</code></p>
  
  <pre><code>var_dump($parent_term); shows object(WP_Error)#980 (2) { ["errors":"WP_Error":private]=&gt; array(1) { ["invalid_term"]=&gt; array(1) { [0]=&gt; string(10) "Empty Term" } } ["error_data":"WP_Error":private]=&gt; array(0) { } } object(WP_Error)#1924 (2) { ["errors":"WP_Error":private]=&gt; array(1) { ["invalid_term"]=&gt; array(1) { [0]=&gt; string(10) "Empty Term" } } ["error_data":"WP_Error":private]=&gt; array(0) { } } object(WP_Error)#1924 (2) { ["errors":"WP_Error":private]=&gt; array(1) { ["invalid_term"]=&gt; array(1) { [0]=&gt; string(10) "Empty Term" } } ["error_data":"WP_Error":private]=&gt; array(0) { } } 
  </code></pre>
  
  <p>I would consider wrapping all this stuff in a function, better.</p>
  
  <p>Thanks</p>