[wp-trac] [WordPress Trac] #9547: Taxonomy - interesting 'unused' term_order column in table term_relationships.

WordPress Trac wp-trac at lists.automattic.com
Wed Jul 27 05:16:24 UTC 2011

#9547: Taxonomy - interesting 'unused' term_order column in table
 Reporter:  michelwppi                         |       Owner:  ryan
     Type:  feature request                    |      Status:  reopened
 Priority:  high                               |   Milestone:  Future
Component:  Taxonomy                           |  Release
 Severity:  normal                             |     Version:  2.8
 Keywords:  taxonomy term_order relationships  |  Resolution:

Comment (by lgedeon):

 No patch needed, actually. Here is the code to use term_order to sort

  * Sort post_tags by term_order
  * @param array $terms array of objects to be replaced with sorted list
  * @param integer $id post id
  * @param string $taxonomy only 'post_tag' is changed.
  * @return array of objects
 function plugin_get_the_ordered_terms ( $terms, $id, $taxonomy ) {
         if ( 'post_tag' != $taxonomy ) // only ordering tags for now but
 could add other taxonomies here.
                 return $terms;

         $terms = wp_cache_get($id, "{$taxonomy}_relationships_sorted");
         if ( false === $terms ) {
                 $terms = wp_get_object_terms( $id, $taxonomy, array(
 'orderby' => 'term_order' ) );
                 wp_cache_add($id, $terms, $taxonomy .

         return $terms;

 add_filter( 'get_the_terms', 'plugin_get_the_ordered_terms' , 10, 4 );

  * Adds sorting by term_order to post_tag by doing a partial register
  * the default
 function plugin_register_sorted_post_tag () {
         register_taxonomy( 'post_tag', 'post', array( 'sort' => true,
 'args' => array( 'orderby' => 'term_order' ) ) );

 add_action( 'init', 'plugin_register_sorted_post_tag' );


 To use this, you will need to add tags in the order you want them to be
 and if you get them out of order you may have to remove some and add them
 back correctly. I might write a better UI later, but for now this at least

 I guess next actions would be to write a patch for object ordering, and to
 come up with a UI(s) for both tag-style and category-style term_ordering.

Ticket URL: <http://core.trac.wordpress.org/ticket/9547#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list