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 have the following code in my sidebar to list all the taxonomy categories.

<div class="left">
    <h1>Categories</h1>

        <?php 
        //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)

        $taxonomy     = 'workcategories';
        $orderby      = 'name'; 
        $show_count   = 0;      // 1 for yes, 0 for no
        $pad_counts   = 0;      // 1 for yes, 0 for no
        $hierarchical = 1;      // 1 for yes, 0 for no
        $title        = '';

        $args = array(
          'taxonomy'     => $taxonomy,
          'orderby'      => $orderby,
          'show_count'   => $show_count,
          'pad_counts'   => $pad_counts,
          'hierarchical' => $hierarchical,
          'title_li'     => $title
        );
        ?>

        <ul>
        <?php wp_list_categories( $args ); ?>
        </ul>
</div><!-- # END left -->

And this code outputs them in alphabetical order. Is there a way that I can order them however I like? My client wants them in a certain order and I have no idea how to do this.

Many thanks E

share|improve this question
add comment

2 Answers 2

By what criterion do you need to order your taxonomy terms?

See this argument-array key:

'orderby'      => $orderby,

Per the documentation for wp_list_categories(), the orderby parameter can take the following values:

  • 'ID' - Default
  • 'name'
  • 'slug'
  • 'count'
  • 'term_group'

Note, you may also want to add the order parameter:

'orderby'      => 'ASC',

This parameter takes:

  • 'ASC'
  • 'DESC'

EDIT

If I wanted to order them by ID - how would I go about that?

Using your code:

    <?php 
    //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)

    $taxonomy     = 'workcategories';
    // THIS IS THE PARAMETER TO CHANGE
    // CHANGE IT FROM 'name' TO 'ID'
    // (NOTE CASE)
    $orderby      = 'ID'; 
    // ADD THE 'order' PARAMETER, TO
    // SPECIFY WHETHER TO SORT ASCENDING
    // OR DESCENDING (AGAIN: NOTE CASE)
    $order        = 'ASC'   // 'ASC' for ascending, 'DESC' for descending
    $show_count   = 0;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';

    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      // DON'T FORGET TO ADD THE 'order' PARAMETER HERE, TOO
      'order'        => $order,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title
    );
    ?>

The ID's don't run in numerical order you see.

Um, that doesn't make sense. IDs are numerical, because they are integers. Thus, ordering by ID results in an ascending or descending list of IDs, in numerical order.

share|improve this answer
    
If I wanted to order them by ID - how would I go about that? The ID's don't run in numerical order you see. –  Evie Milo Oct 25 '11 at 15:27
    
See updated answer, with 'orderby' => 'ID' and 'order' => 'ASC' integrated into your example code. –  Chip Bennett Oct 25 '11 at 15:41
    
What I mean is that I want the IDs to run in this order - 4,5,18,7,10 - I've tried deleting the taxonmies and re-adding them to reset the order, but each time I re-add them they get the same ID numbers so I'm stuck with them. –  Evie Milo Oct 25 '11 at 15:51
    
"What I mean is that I want the IDs to run in this order - 4,5,18,7,10" - then that means that you're not ordering the taxonomies by ID; you're ordering them arbitrarily. You'll need to look into improving/changing your naming/organization schema, or else find a Plugin that allows for such arbitrary ordering. –  Chip Bennett Oct 25 '11 at 15:54
    
How can I change the IDs for the taxonomies? I thought that by deleting them this would enable me to add them in the order that I want them in and new IDs would be created. –  Evie Milo Oct 26 '11 at 12:31
add comment

You can't impose a manual ordering of categories natively in Wordpress.

The great thing about Wordpress is that it has a huge developer community behind it. A quick search gave me this plugin that pretty much gives you exactly the feature you are looking for.

share|improve this answer
    
super - thanks for that - I'll give it a go! –  Evie Milo Oct 25 '11 at 15:26
add comment

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.