WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

By default WordPress orders custom taxonomies (as tags in this case) by alphabetical order not by the order they were entered in the tag box.

Is anyone aware of a way to show the custom taxonomies in the order they were entered in the post edit screen?

The url in question is: http://granadatheater.com/

The GGW (Goes Good With) artists are currently in alphabetical order and they want it changed so that they are ordered the same way they were entered.

So if the enter it Artist1, Artist3, Artist2 that's how it should show up on the frontend of the site.

share|improve this question
You mean entering order on a per post base? – hakre Jan 21 '11 at 17:49
Maybe order by id? – Bainternet Jan 21 '11 at 22:53
Best I can tell they are displayed in alphabetic order, so I'm probably not understanding the question. Where exactly do you want this? Can you give a screenshot and an example URL where you'll find what you want changed? – MikeSchinkel Jan 22 '11 at 7:56
up vote 1 down vote accepted

This isn't possible "out of the box"...

The default 'orderby' options are (ascending or descending)

  • ID name
  • Default
  • slug
  • count
  • term_group

These are all detailed in the codex.


That said there are some clever ladies & gents here. If anyone can solve it, one of these guys can i'm sure!

share|improve this answer

After quite a bit of searching and extensive tests, I found the answer.

Add this code to your theme's functions.php:

function set_the_terms_in_order ( $terms, $id, $taxonomy ) {
    $terms = wp_cache_get( $id, "{$taxonomy}_relationships_sorted" );
    if ( false === $terms ) {
        $terms = wp_get_object_terms( $id, $taxonomy, array( 'orderby' => 'term_order' ) );
        wp_cache_add($id, $terms, $taxonomy . '_relationships_sorted');
    return $terms;
add_filter( 'get_the_terms', 'set_the_terms_in_order' , 10, 4 );

function do_the_terms_in_order () {
    global $wp_taxonomies;  //fixed missing semicolon
    // the following relates to tags, but you can add more lines like this for any taxonomy
    $wp_taxonomies['post_tag']->sort = true;
    $wp_taxonomies['post_tag']->args = array( 'orderby' => 'term_order' );    
add_action( 'init', 'do_the_terms_in_order');

(Credit: this is based on - but improved - http://wordpress.kdari.net/2011/07/listing-tags-in-custom-order.html)

share|improve this answer

I've been struggling to find the answer to alphabetical child terms of a custom taxonomy ... I wouldn't recommend altering core WP files, so here's what I added to my taxonomy.php file to list out custom taxonomy descriptions, with links to child terms in alphabetical order. Modify to suit your needs, I hope this helps someone out there.

// Get Main Taxonomy for use in template file
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$termTaxonomy = $term->taxonomy;

<h1><?php echo apply_filters( 'the_title', $term->name ); ?></h1>

<?php // test for description before unleashing a div 
if ( !empty( $term->description ) ): 
  echo '<div class="description">';
  echo $term->description;
  echo '</div>;
endif; ?>

// Now get children terms, using get_term & 'child_of' get's us alphabetical order
$termchildren = get_terms( $termTaxonomy, array(
  'child_of'     => $term->term_id,
  'hierarchical' => 0,
  'fields'       => 'ids',
  'hide_empty'   => 0
) );

// Make an alphabetical linked list
echo '<ul>';
foreach ($termchildren as $child) {
  $term = get_term_by( 'id', $child, $termTaxonomy );

  // Modify this echo to customize the output for each child term
  echo '<li><a href="' . get_term_link( $term->name, $termTaxonomy ) . '" alt="' .$term->description. '">' . $term->name . '</a></li>';
echo '</ul>';
share|improve this answer

Your Answer


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.