[wp-trac] [WordPress Trac] #40496: get_the_terms() doesn't respect register_taxonomy()'s 'orderby' => 'term_order'

WordPress Trac noreply at wordpress.org
Fri Jun 30 13:12:57 UTC 2017

#40496: get_the_terms() doesn't respect register_taxonomy()'s 'orderby' =>
 Reporter:  danielbachhuber          |       Owner:  boonebgorges
     Type:  defect (bug)             |      Status:  closed
 Priority:  normal                   |   Milestone:  4.7.5
Component:  Taxonomy                 |     Version:  4.7
 Severity:  normal                   |  Resolution:  fixed
 Keywords:  has-patch needs-testing  |     Focuses:

Comment (by GhostToast):

 @boonebgorges @danielbachhuber - I stumbled upon this trac ticket, when
 working with WP 4.8 I noticed I was getting duplicate terms (double the
 amount) when using `get_the_terms()` on a custom post type with custom
 taxonomies. I followed it along to the line where it does the
 `array_merge()` with a (seemingly) redundant call to `get_terms()`:

 $terms = array_merge( $terms, get_terms( $args ) );

 This perplexed me for a while until I experimented enough to discover that
 if my custom post type had at least 1 taxonomy registered to it which _did
 not_ provide this in its setup:
 'args' => [
         'orderby' => 'term_order',
 then the problem was resolved!

 I'm not sure if this is a new bug or a re-introduced one, but wanted to
 point it out.

 To reproduce, try to view a custom post type's terms, fetched via
 `get_the_terms()`, where the custom post type has only taxonomies
 registered to it which include this manually-declared orderby. You should
 end up seeing twice as many terms (even if there is only 1 term to view).

Ticket URL: <https://core.trac.wordpress.org/ticket/40496#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list