Change default ordering of taxonomy terms – pre_get_terms

enter image description here

I wanted to change the default taxonomy terms order by its ‘term_order’ value instead of ‘name’ in admin side. So I tried something like below. But it doesn’t work and php memory exhaust.

function uc_order_term( $wp_query ) {
    $wp_query->query(
        array(
            'taxonomy' => 'category',
            'orderby' => 'term_order',
            'order' => 'ASC'
        )
    );
}
add_action( 'pre_get_terms', 'uc_order_term');

However in similar way I tried to sort posts by menu_order and it works.

function uc_order_post( $wp_query ) {

            $wp_query->set('orderby', 'menu_order');
            $wp_query->set('order', 'ASC');

}
add_action( 'pre_get_posts', 'uc_order_post', 1 );

Read more here:: Change default ordering of taxonomy terms – pre_get_terms

Leave a Reply

Your email address will not be published. Required fields are marked *