Alert: 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.

WP_Tax_Query::clean_query() WordPress Method

The WP_Tax_Query::clean_query() method is used to clean up the tax query after a request has been made. This is done by removing any unused taxonomies and terms from the query. This method also ensures that the correct number of taxonomies and terms are being used for the request.

WP_Tax_Query::clean_query( array $query ) #

Validates a single query.


Parameters

$query

(array)(Required)The single query. Passed by reference.


Top ↑

Source

File: wp-includes/class-wp-tax-query.php

	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' );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.