WP_Tax_Query::__construct() WordPress Method

The WP_Tax_Query::__construct() method allows you to construct a new WP_Tax_Query object. This object can be used to query for posts that have a certain taxonomy term assigned to them.

WP_Tax_Query::__construct( array $tax_query ) #

Constructor.


Parameters

$tax_query

(array)(Required)Array of taxonomy query clauses.

  • 'relation'
    (string) Optional. The MySQL keyword used to join the clauses of the query. Accepts 'AND', or 'OR'. Default 'AND'.
  • '...$0'
    (array) An array of first-order clause parameters, or another fully-formed tax query.
    • 'taxonomy'
      (string) Taxonomy being queried. Optional when field=term_taxonomy_id.
    • 'terms'
      (string|int|array) Term or terms to filter by.
    • 'field'
      (string) Field to match $terms against. Accepts 'term_id', 'slug', 'name', or 'term_taxonomy_id'. Default: 'term_id'.
    • 'operator'
      (string) MySQL operator to be used with $terms in the WHERE clause. Accepts 'AND', 'IN', 'NOT IN', 'EXISTS', 'NOT EXISTS'. Default: 'IN'.
    • 'include_children'
      (bool) Optional. Whether to include child terms. Requires a $taxonomy. Default: true.


Top ↑

Source

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

	public function __construct( $tax_query ) {
		if ( isset( $tax_query['relation'] ) ) {
			$this->relation = $this->sanitize_relation( $tax_query['relation'] );
		} else {
			$this->relation = 'AND';
		}

		$this->queries = $this->sanitize_query( $tax_query );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.1.0Added support for $operator 'NOT EXISTS' and 'EXISTS' values.
3.1.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.