Title: WP_Tax_Query::__construct
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Tax_Query::__construct( array $tax_query )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#wp--skip-link--target)

Constructor.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#parameters)󠁿

 `$tax_query`arrayrequired

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.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-tax-query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-tax-query.php#L115)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-tax-query.php#L115-L123)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Tax_Query::sanitize_relation()](https://developer.wordpress.org/reference/classes/wp_tax_query/sanitize_relation/)`wp-includes/class-wp-tax-query.php` |

Sanitizes a ‘relation’ operator.

  | 
| [WP_Tax_Query::sanitize_query()](https://developer.wordpress.org/reference/classes/wp_tax_query/sanitize_query/)`wp-includes/class-wp-tax-query.php` |

Ensures the ‘tax_query’ argument passed to the class constructor is well-formed.

  |

| Used by | Description | 
| [WP_Query::parse_tax_query()](https://developer.wordpress.org/reference/classes/wp_query/parse_tax_query/)`wp-includes/class-wp-query.php` |

Parses various taxonomy related query vars.

  | 
| [get_tax_sql()](https://developer.wordpress.org/reference/functions/get_tax_sql/)`wp-includes/taxonomy.php` |

Given a taxonomy query, generates SQL to be appended to a main query.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_tax_query/__construct/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | Added support for `$operator` ‘NOT EXISTS’ and `'EXISTS'` values. | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_tax_query%2F__construct%2F)
before being able to contribute a note or feedback.