Organising Taxonomy categories

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.

Read More

Many thanks
E

Related posts

Leave a Reply

2 comments

  1. 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.

  2. 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.