When adding queries to tax_query: if the query's field is term_taxonomy_id, don't require taxonomy to be specified. In WP_Tax_Query::transform_query(), $query['taxonomy'] is never checked for the 'term_taxonomy_id' case because 'term_taxonomy_id' is the primary key being looked up.

Adds unit tests.

Props helen.
Fixes #25284.


Built from https://develop.svn.wordpress.org/trunk@28562


git-svn-id: http://core.svn.wordpress.org/trunk@28388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-05-23 19:59:14 +00:00
parent 5b5b756edf
commit 44c4b365a0

View File

@ -632,15 +632,15 @@ class WP_Tax_Query {
/**
* List of taxonomy queries. A single taxonomy query is an associative array:
* - 'taxonomy' string The taxonomy being queried
* - 'taxonomy' string The taxonomy being queried. Optional when using the term_taxonomy_id field.
* - 'terms' string|array The list of terms
* - 'field' string (optional) Which term field is being used.
* Possible values: 'term_id', 'slug' or 'name'
* Possible values: 'term_id', 'slug', 'name', or 'term_taxonomy_id'
* Default: 'term_id'
* - 'operator' string (optional)
* Possible values: 'AND', 'IN' or 'NOT IN'.
* Default: 'IN'
* - 'include_children' bool (optional) Whether to include child terms.
* - 'include_children' bool (optional) Whether to include child terms. Requires that a taxonomy be specified.
* Default: true
*
* @since 3.1.0
@ -818,7 +818,15 @@ class WP_Tax_Query {
* @param array &$query The single query
*/
private function clean_query( &$query ) {
if ( ! taxonomy_exists( $query['taxonomy'] ) ) {
if ( empty( $query['taxonomy'] ) ) {
if ( 'term_taxonomy_id' !== $query['field'] ) {
$query = new WP_Error( 'Invalid taxonomy' );
return;
}
// so long as there are shared terms, include_children requires that a taxonomy is set
$query['include_children'] = false;
} elseif ( ! taxonomy_exists( $query['taxonomy'] ) ) {
$query = new WP_Error( 'Invalid taxonomy' );
return;
}