[wp-trac] [WordPress Trac] #34996: Ordering taxonomies by term meta

WordPress Trac noreply at wordpress.org
Thu Dec 10 23:48:32 UTC 2015


#34996: Ordering taxonomies by term meta
-------------------------+-----------------------------
 Reporter:  eherman24    |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  4.4
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 With the release of 4.4 and the new term meta functionality, it seems that
 there is no way to order taxonomies by assigned term meta.

 For example, I have a custom post type, with a custom taxonomy and each
 term has term meta associated to it ('tax_position'). In my instance, the
 'tax_position' term meta value is the order that the taxonomies should
 ideally display in.

 Using the filter `get_terms_args`, there doesn't seem to be a way to pass
 in a `meta_key` value. We have an `orderby`, `order` and a `meta_query`
 argument that we can utilize, but no way to specify a `meta_key`.

 The `meta_query` argument works as intended, and allows me to limit the
 returned terms by individual integers or within a range.

 Passing in `meta_key` has no effect.

 Here is the snippet I was working with when I encountered this issue:

 {{{
 add_filter( 'get_terms_args', 're_order_taxonomies_by_position', 10, 2 );
 /*
 *       Re-Order the taxonomies based on the tax_position
 *       @since 0.1
 */
 function re_order_taxonomies_by_position( $args, $taxonomies ) {
         $args['meta_key'] = 'tax_position';
         $args['orderby'] = 'meta_value_num';
         return $args;
 }
 }}}


 Sorting posts by meta is easily do-able using:

 {{{
 $query = new WP_Query( array(
   'meta_key'   => 'position',
   'orderby'    => 'meta_value_num',
   'order'      => 'ASC'
 ) );
 }}}


 This may be a possible enhancement to the new term meta functionality
 included in 4.4.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34996>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list