Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to make an exception for my custom taxonomy order. Sometimes you need to put "Other" option as last option but when calling taxonomies with "orderby=name", sadly "Other" term is not listing as last option. Is there any proper way for this exception?

share|improve this question
    
Is this about front or backend? –  brasofilo Jun 14 '12 at 14:16

1 Answer 1

up vote 4 down vote accepted
+50

Here is the example of get_terms in the Codex:

$terms = get_terms("my_taxonomy");
 $count = count($terms);
 if ( $count > 0 ){
     echo "<ul>";
     foreach ( $terms as $term ) {
       echo "<li>" . $term->name . "</li>";

     }
     echo "</ul>";
 }

Lets say there was an 'other' term in my_taxonomy. To place it at the end as you requested, we would check each term if it matched, and put it aside for safekeeping. Then, when the loop is finished, we would check if it was found and display it at the end.

e.g.

 $terms = get_terms("my_taxonomy");
 $count = count($terms);
 if ( $count > 0 ){
     echo "<ul>";
     $other_term = null;
     foreach ( $terms as $term ) {
       if($term->name == 'other'){
           $other_term = $term;
       } else {
           echo "<li>" . $term->name . "</li>";
       }
     }
     if($other_term != null){
       echo "<li>" . $other_term->name . "</li>";
     }
     echo "</ul>";
 }

Think of it as a queue, first in first out, only when the person called 'other' arrives at the window for processing, a guard grabs him and pulls him aside. When the queue is empty and everyone has been processed, the guard puts the 'other' person back in the queue at the end.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.