How can I custom order the results from wp_list_categories?

There is an unused column, term_order, in the wp_term_relationships table that you can use to assign a custom order to the terms within your taxonomy. The order is set at 0 by default and it will take a custom query to get the order back and another solution to set the order.

Example query:

function wpse_order_taxes() {
        global $wpdb;
        $results = $wpdb->get_results ( "SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category'  ORDER BY term_order ASC LIMIT 0, 10" );
        $categories = array();
        foreach ( $results as $cat ) {
            array_push( $categories, $cat->slug );
        }
        return $categories;
    }

This would give you back an array of terms ordered by the custom order.

Leave a Comment

error code: 523