Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#44695 new defect (bug)

WP_Term_Query unexpected 'orderby' behaviour.

Reported by: williampatton's profile williampatton Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.7
Component: Query Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description (last modified by williampatton)

I expected that orderby would behave in a similar way with WP_Term_Query as it does on other *_Query classes but it seems that meta_value_date and possibly some others is unsupported. Additionally meta_type doesn't function as expected either.

These args:

$args = array(
	'taxonomy'      => 'issues',
	'number'        => 5,
	'meta_key'      => 'issue_date',
	'meta_type'     => 'DATE',
	'orderby'       => 'meta_value_date',

Result in this query that has disregarded both meta_type and orderby in it's generation:

SELECT DISTINCT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_termmeta ON ( t.term_id = wp_termmeta.term_id ) INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('issues') AND tt.count > 0 AND ( wp_termmeta.meta_key = 'issue_date' ) ORDER BY ASC LIMIT 5

Could we get similar support for same named keys in WP_Term_Query as we have in other queries?

Change History (3)

#1 @williampatton
6 years ago

  • Description modified (diff)

#2 @SergeyBiryukov
6 years ago

  • Keywords needs-patch needs-unit-tests added

This ticket was mentioned in Slack in #core by williampatton. View the logs.

5 years ago

Note: See TracTickets for help on using tickets.