[wp-trac] [WordPress Trac] #29859: get_terms on hierarchical taxonomy fails when 'fields' arg contains 'id=>name' OR 'id=>slug'

WordPress Trac noreply at wordpress.org
Sat Oct 4 03:19:19 UTC 2014


#29859: get_terms on hierarchical taxonomy fails when 'fields' arg contains
'id=>name' OR 'id=>slug'
----------------------------------+-----------------------------
 Reporter:  technical_mastermind  |      Owner:
     Type:  defect (bug)          |     Status:  new
 Priority:  normal                |  Milestone:  Awaiting Review
Component:  Taxonomy              |    Version:  trunk
 Severity:  normal                |   Keywords:
  Focuses:                        |
----------------------------------+-----------------------------
 When using get_terms() and passing in 'id=>name' or 'id=>slug' as the
 value for the 'fields' argument, it fails to return the expected array if
 you are working with a hierarchical taxonomy.

 For example, this code block works:
 {{{
 $terms = get_terms( 'post_tag', array( 'fields' => 'id=>name' ) );
 }}}

 This code block does not work:
 {{{
 $terms = get_terms( 'category', array( 'fields' => 'id=>name' ) );
 }}}

 The difference being that 'post_tag' is a non-hierarchical taxonomy while
 'category' is a hierarchical taxonomy. I have tested this in several
 versions of WordPress, it is still present in 4.0. I have created a patch
 for it against trunk as well as written more in-depth unit tests to test
 the functionality of the get_terms function. Note that 4 of the unit tests
 I wrote fail before the get_terms patch is applied, none of the unit tests
 I wrote fail after the patch is applied.

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


More information about the wp-trac mailing list