{"id":17691785,"date":"2024-04-16T21:03:45","date_gmt":"2024-04-16T21:03:45","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/sorting-select-lists\/"},"modified":"2024-04-16T21:03:45","modified_gmt":"2024-04-16T21:03:45","slug":"sorting-select-lists","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/sorting-select-lists\/","title":{"rendered":"Sorting select lists?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Is it possible to sort select lists? I have tried hacking the get_categories() call when loading $terms by adding \u201corderby\u201d =&gt; \u201cname\u201d and \u201corder\u201d =&gt; \u201cASC\u201d but it doesn\u2019t seem to work. The only workaround I have found is to create a function and run the $terms through it before they are displayed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function w2dc_wmd_order_terms( $terms )\n{\n\u00a0 \u00a0 \u00a0 \u00a0 $terms_order = &#091;];\n\u00a0 \u00a0 \u00a0 \u00a0 foreach( $terms as $t )\n\u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 $terms_order&#091; $t-&gt;slug ] = $t;\n\u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 ksort( $terms_order );\n\u00a0 \u00a0 \u00a0 \u00a0 $terms = &#091;];\n\u00a0 \u00a0 \u00a0 \u00a0 foreach( $terms_order as $term =&gt; $t )\n\u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $terms&#091;] = $t;\n\u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 return $terms;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<\/p>\n","protected":false},"template":"","class_list":["post-17691785","topic","type-topic","status-publish","hentry","topic-tag-add_filter","topic-tag-enhancements","topic-tag-terms"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17691785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17691785\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=17691785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}