On this page
WP_Tax_Query::clean_query( array $query )
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Validates a single query.
Parameters
$queryarray Required-
The single query. Passed by reference.
Source
File: wp-includes/class-wp-tax-query.php. View all references
private function clean_query( &$query ) {
if ( empty( $query['taxonomy'] ) ) {
if ( 'term_taxonomy_id' !== $query['field'] ) {
$query = new WP_Error( 'invalid_taxonomy', __( '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', __( 'Invalid taxonomy.' ) );
return;
}
if ( 'slug' === $query['field'] || 'name' === $query['field'] ) {
$query['terms'] = array_unique( (array) $query['terms'] );
} else {
$query['terms'] = wp_parse_id_list( $query['terms'] );
}
if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) {
$this->transform_query( $query, 'term_id' );
if ( is_wp_error( $query ) ) {
return;
}
$children = array();
foreach ( $query['terms'] as $term ) {
$children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) );
$children[] = $term;
}
$query['terms'] = $children;
}
$this->transform_query( $query, 'term_taxonomy_id' );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_parse_id_list() wp-includes/functions.php | Cleans up an array, comma- or space-separated list of IDs. |
| WP_Tax_Query::transform_query() wp-includes/class-wp-tax-query.php | Transforms a single query, from one field to another. |
| get_term_children() wp-includes/taxonomy.php | Merges all term children into a single array of their IDs. |
| taxonomy_exists() wp-includes/taxonomy.php | Determines whether the taxonomy name exists. |
| is_taxonomy_hierarchical() wp-includes/taxonomy.php | Determines whether the taxonomy object is hierarchical. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_Tax_Query::get_sql_for_clause() wp-includes/class-wp-tax-query.php | Generates SQL JOIN and WHERE clauses for a “first-order” query clause. |
Changelog
| Version | Description |
|---|---|
| 3.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_tax_query/clean_query