[wp-trac] [WordPress Trac] #5857: an object's terms should be positionable

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

#5857: an object's terms should be positionable
 Reporter:  andy                           |       Owner:  ryan
     Type:  enhancement                    |      Status:  closed
 Priority:  normal                         |   Milestone:  2.5
Component:  General                        |     Version:
 Severity:  normal                         |  Resolution:  fixed
 Keywords:  taxonomy sort order has-patch  |
Changes (by lgedeon):

 * cc: luke.gedeon@… (added)


 Based on the code above (which is now in core), here is the code to use
 term_order to sort tags. It can, of course, be adapted for other

  * 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/5857#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list