{"id":48217,"date":"2011-07-04T08:00:00","date_gmt":"2011-07-04T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/2024\/02\/22\/custom-taxonomy-sort\/"},"modified":"2011-12-14T00:42:00","modified_gmt":"2011-12-14T00:42:00","slug":"custom-taxonomy-sort","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/custom-taxonomy-sort\/","title":{"rendered":"Custom Taxonomy Sort"},"content":{"rendered":"<p>Surprisingly, WordPress does not provide a mechanism for sorting taxonomies by a custom defined order. Taxonomies can only be sorted by name or id. Custom Taxonomy Sort allows the average user a mechanism to define and display terms in a specified order. After installing Custom Taxonomy Sort, each taxonomy term will have the ability to have a \u201ctax-order\u201d value associated with it. This order is specified by doing the following:<\/p>\n<ol>\n<li>Go to any taxonomy add or edit screen (e.g., wp-admin\/edit-tags.php?taxonomy=category)<\/li>\n<li>Fill in a numeric value for the \u201cOrder\u201d field. By default, the order will be ascending, meaning it will sort from low to high (e.g., 1, 2, 3). These values can be added on the Add Taxonomy screen, the Edit Taxonomy screen, or through the Quick Edit panel.<\/li>\n<li>Observe all of your terms automagically being sorted in the order you specified<\/li>\n<\/ol>\n<p>Custom Taxonomy Sort automatically applies the sort order to all instances in which the terms are displayed. All you need to do is define that order.<\/p>\n<h4>Manual Mode<\/h4>\n<p>In addition to automatically sorting the terms, Custom Taxonomy Sort allows developers to override the automatic sort to offer finer control over how terms are displayed in different parts of WordPress. Manual mode can be started by changing \u201cAutomatic Sort\u201d to \u201cOff\u201d in the Custom Taxonomy Sort Settings page (wp-admin\/options-general.php?page=custom-taxonomy-sort-settings). Once \u201cAutomatic Sort\u201d is switched to \u201cOff\u201d, the terms will no longer be sorted automatically by the custom order. Instead, the custom sort order can be envoked with a new parameter for the \u201corderby\u201d argument. Custom Taxonomy Sort allows you to use the following argument to access a custom sorted list of terms using \u201cget_terms\u201d<\/p>\n<pre><code><?php get_terms('orderby=custom_sort'); ?>\n<\/code><\/pre>\n<p>Voila! Now, your terms will only be sorted by the specified order in the places that you want it sorted in this order. All other instances of displaying terms will revert to WordPress\u2019 default of sorting the terms by name. Additionally, you can specifically have the terms sort in ascending (\u2018ASC\u2019; default; e.g., 1, 2, 3) or descending (\u2018DESC\u2019; e.g., 3, 2, 1) order by adding the \u201corder\u201d argument.<\/p>\n<pre><code><?php get_terms('orderby=custom_sort&order=ASC'); ?>\n\n<?php get_terms('orderby=custom_sort&order=DESC'); ?>\n<\/code><\/pre>\n<h4>Acknowledgements<\/h4>\n<ul>\n<li>Thanks to Jacob M Goldman for his excellent <a href=\"https:\/\/wordpress.org\/extend\/plugins\/simple-term-meta\/\" rel=\"ugc\">Simple Term Meta plugin<\/a>, which made programming the term meta quite simple. <\/li>\n<li>Thanks to hydrowire <a href=\"https:\/\/wordpress.org\/support\/topic\/plugin-custom-taxonomy-sort-error-in-quick-edit-post\" rel=\"ugc\">for pointing out a bug<\/a> fixed in 1.1.1<\/li>\n<li>Thanks to \u201cMosey\u201d for pointing out a bug with a situation in which order did not work for a custom taxonomy<\/li>\n<li>Thanks to DUCK__BOY1981 for pointing out a bug where the column values where overridden inappropriately<\/li>\n<li>Thanks to @martindj for pointing out a bug where the column value returned incorrectly<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Custom Taxonomy Sort allows you to explicitly control the sort order of all taxonomy terms.<\/p>\n","protected":false},"author":65,"featured_media":229092,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Custom Taxonomy Sort - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Custom Taxonomy Sort allows you to explicitly control the sort order of all taxonomy terms."},"footnotes":""},"categories":[1],"tags":[11,5721,14],"class_list":["post-48217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-category","tag-sort","tag-taxonomy"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/48217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=48217"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/48217\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/229092"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=48217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=48217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=48217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}