WordPress.org

Make WordPress Core

Opened 16 months ago

Last modified 3 months ago

#44695 new defect (bug)

WP_Term_Query unexpected 'orderby' behaviour.

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

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 t.name 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
16 months ago

  • Description modified (diff)

#2 @SergeyBiryukov
16 months ago

  • Keywords needs-patch needs-unit-tests added

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


3 months ago

Note: See TracTickets for help on using tickets.