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
- __construct()Constructor.
- sanitize_query()Ensures the 'tax_query' argument passed to the class constructor is well-formed.
- sanitize_relation()Sanitizes a 'relation' operator.
- is_first_order_clause()Determines whether a clause is first-order.
- get_sql()Generates SQL clauses to be appended to a main query.
- get_sql_clauses()Generates SQL clauses to be appended to a main query.
- get_sql_for_query()Generates SQL clauses for a single query array.
- get_sql_for_clause()Generates SQL JOIN and WHERE clauses for a "first-order" query clause.
- find_compatible_table_alias()Identifies an existing table alias that is compatible with the current query clause.
- clean_query()Validates a single query.
- transform_query()Transforms a single query, from one field to another.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.