wppaste
WordPress

WP_Tax_Query

Since
3.1.0
Source
wp-includes/class-wp-tax-query.php:22
Core class used to implement taxonomy queries for the Taxonomy API.

Description

Used for generating SQL clauses that filter a primary query according to object taxonomy terms.

WP_Tax_Query is a helper that allows primary query classes, such as WP_Query, to filter their results by object metadata, by generating JOIN and WHERE subclauses to be attached to the primary SQL query string.

Compatibility

WordPress
since 3.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 7

$queriesarraypublic
Array of taxonomy queries.
$relationstringpublic
The relation between the queries. Can be one of 'AND' or 'OR'.
$no_resultsarray<string,private static
Standard response when the query should not return any rows.
$table_aliasesarrayprotected
A flat list of table aliases used in the JOIN clauses.
$queried_termsarraypublic
Terms and taxonomies fetched by this query.
$primary_tablestringpublic
Database table that where the metadata's objects are stored (eg $wpdb->users).
$primary_id_columnstringpublic
Column in 'primary_table' that represents the ID of the object.

Methods · 11

Source code

#[AllowDynamicProperties]class WP_Tax_Query { 	/**	 * Array of taxonomy queries.	 *	 * See WP_Tax_Query::__construct() for information on tax query arguments.	 *	 * @since 3.1.0	 * @var array	 */	public $queries = array(); 	/**	 * The relation between the queries. Can be one of 'AND' or 'OR'.	 *	 * @since 3.1.0	 * @var string	 */	public $relation; 	/**	 * Standard response when the query should not return any rows.	 *	 * @since 3.2.0	 * @var array<string, array<string>>	 */	private static $no_results = array(		'join'  => array( '' ),		'where' => array( '0 = 1' ),	); 	/**	 * A flat list of table aliases used in the JOIN clauses.	 *	 * @since 4.1.0	 * @var array	 */	protected $table_aliases = array(); 	/**	 * Terms and taxonomies fetched by this query.	 *	 * We store this data in a flat array because they are referenced in a	 * number of places by WP_Query.	 *	 * @since 4.1.0	 * @var array	 */	public $queried_terms = array(); 	/**	 * Database table that where the metadata's objects are stored (eg $wpdb->users).	 *	 * @since 4.1.0	 * @var string	 */	public $primary_table; 	/**	 * Column in 'primary_table' that represents the ID of the object.	 *	 * @since 4.1.0	 * @var string	 */	public $primary_id_column; 	/**	 * Constructor.	 *	 * @since 3.1.0	 * @since 4.1.0 Added support for `$operator` 'NOT EXISTS' and 'EXISTS' values.	 *	 * @param array $tax_query {	 *     Array of taxonomy query clauses.	 *	 *     @type string $relation Optional. The MySQL keyword used to join	 *                            the clauses of the query. Accepts 'AND', or 'OR'. Default 'AND'.	 *     @type array  ...$0 {	 *         An array of first-order clause parameters, or another fully-formed tax query.

Changelog

Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-tax-query.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.