Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#44505 closed enhancement (duplicate)

term_order is an invalid orderby parameter in WP_Term_Query::get_terms()

Reported by: swinggraphics's profile swinggraphics Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Taxonomy Keywords:
Focuses: Cc:

Description

This is a follow-up to #35381.

I'm wondering why term_order is not allowed as the orderby parameter in WP_Term_Query::get_terms() for functions like get_terms(). It is specifically invalidated on line 388. Granted, term_order isn't used for much in core right now, but the column is there, and one generally expects any column heading to be a valid orderby parameter. The workaround is to create custom meta for the terms and add a meta_query. There are examples on StackExchange/Overflow of people looking for a remedy. In fact, there is an example of this on trac ticket:34996, where the example used for justifying the addition of meta_query only exists because term_order is a rejected orderby.

I'm marking this as an "enhancement" because the code does what is intended, but unless one delves into the source code, it feels like a bug.

Change History (2)

#1 @boonebgorges
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @swinggraphics - Thanks for your ticket, and welcome to WordPress Trac!

The term_order column is in the wp_term_relationships table. As such, it's only possible to use that column for ordering when joining against the relationships table, and WP_Term_Query only does this when object_ids are passed to the query. So the limitation you've cited in WP_Term_Query is technical - it's not possible to remove it.

The ability to specify term order would be an interesting feature, and has been proposed in a number of places. See #30244, #9547. These solutions would have to use something other than the term_order column in wp_term_relationships, for backward compatibility and other reasons, but those tickets have some good discussion about what such a feature might look like.

#2 @boonebgorges
7 years ago

Duplicate of #30244.

Note: See TracTickets for help on using tickets.