Sorting select lists? | WordPress.org

[ad_1]

Is it possible to sort select lists? I have tried hacking the get_categories() call when loading $terms by adding “orderby” => “name” and “order” => “ASC” but it doesn’t seem to work. The only workaround I have found is to create a function and run the $terms through it before they are displayed:

function w2dc_wmd_order_terms( $terms )
{
        $terms_order = [];
        foreach( $terms as $t )
        {
         $terms_order[ $t->slug ] = $t;
        }
        ksort( $terms_order );
        $terms = [];
        foreach( $terms_order as $term => $t )
        {
          $terms[] = $t;
        }
        return $terms;
}

Of course this will get overwritten each time the plugin is updated. Can you please add a hook or filter to those terms before they are displayed?

Thank you!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer