wp_list_categories: order by term order?

The wp_list_categories() function calls the get_categories() function, that’s a wrapper for the get_terms() function, that creates an instance of the WP_Term_Query class. It doesn’t look like it supports ordering by term order.

If the plugin uses the term_order column in the wp_terms table, then you can try to add a support for it’s ordering, via the get_terms_orderby filter:

add_filter( 'get_terms_orderby', function( $orderby, $qv, $taxonomy )
{
    // Only target the category taxonomy
    if( 'category' !== $taxonomy )
        return $orderby;

    // Support orderby term_order
    if( isset( $qv['orderby'] ) && 'term_order' === $qv['orderby'] )
        $orderby = 't.term_order';

    return $orderby;
}, 10, 3 );

where we only support this for the category taxonomy.

Another approach is to add the filter and remove it right after your wp_list_categories() call.

Leave a Comment

error code: 523