Taxonomy: Improve back compat of values passed to 'terms_clauses' filter.

Prior to the introduction of `WP_Term_Query`, the 'orderby' clause
passed to the 'terms_clauses' filter was prefixed by `ORDER BY`. After
`WP_Term_Query`, this was not the case; `ORDER BY` was added after the
filter. As such, plugins filtering 'terms_clauses' and returning an
'orderby' clause beginning with `ORDER BY` resulted in invalid syntax
when `WP_Term_Query` prepended a second `ORDER BY` keyword to
the clause.

This changeset rearranges the way the 'orderby' clause is built so that
it will be passed to 'terms_clauses' in the previous format.

Fixes #37378.
Built from https://develop.svn.wordpress.org/trunk@38099


git-svn-id: http://core.svn.wordpress.org/trunk@38040 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2016-07-19 02:13:28 +00:00
parent 093b16dfcd
commit 01b9ca2292
2 changed files with 6 additions and 2 deletions

View File

@ -384,6 +384,10 @@ class WP_Term_Query {
} }
$orderby = $this->parse_orderby( $this->query_vars['orderby'] ); $orderby = $this->parse_orderby( $this->query_vars['orderby'] );
if ( $orderby ) {
$orderby = "ORDER BY $orderby";
}
$order = $this->parse_order( $this->query_vars['order'] ); $order = $this->parse_order( $this->query_vars['order'] );
if ( $taxonomies ) { if ( $taxonomies ) {
@ -618,7 +622,7 @@ class WP_Term_Query {
$this->sql_clauses['select'] = "SELECT $distinct $fields"; $this->sql_clauses['select'] = "SELECT $distinct $fields";
$this->sql_clauses['from'] = "FROM $wpdb->terms AS t $join"; $this->sql_clauses['from'] = "FROM $wpdb->terms AS t $join";
$this->sql_clauses['orderby'] = $orderby ? "ORDER BY $orderby $order" : ''; $this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : '';
$this->sql_clauses['limits'] = $limits; $this->sql_clauses['limits'] = $limits;
$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.6-beta3-38098'; $wp_version = '4.6-beta3-38099';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.