Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 112646

vtxyzzy on "displaying custom taxonomies in particular order"

$
0
0

Here is one way to get the terms in order in an array.

$terms = get_the_terms($post->ID,'category');
$sorted_terms = array();
$find_parent = 0;
for( $i = 0; $i < sizeof($terms); ++$i) {
   foreach ($terms as $term) {
      if ($term->parent == $find_parent) {
         $find_parent = $term->term_id;
         $sorted_terms[] = $term;
      }
   }
}

The sorted_terms array now contains the terms in order. $sorted_terms[0] will contain the country term, $sorted_terms[1] will contain the state term, and $sorted_terms[2] will contain the city term.


Viewing all articles
Browse latest Browse all 112646

Trending Articles