WP_Meta_Query
- Since
- 3.2.0
- Source
wp-includes/class-wp-meta-query.php:22
Core class used to implement meta queries for the Meta API.
Description
Used for generating SQL clauses that filter a primary query according to metadata keys and values.
WP_Meta_Query is a helper that allows primary query classes, such as WP_Query and WP_User_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.2.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).
Hooks and filters fired · 2
Every hook that fires from inside WP_Meta_Query, in the order it appears in the class, grouped by the method that fires it.
WP_Meta_Query::get_sql()
- apply_filters( get_meta_sql )filter line 395
Properties · 9
$queriesarraypublic- Array of metadata queries.
$relationstringpublic- The relation between the queries. Can be one of 'AND' or 'OR'.
$meta_tablestringpublic- Database table to query for the metadata.
$meta_id_columnstringpublic- Column in meta_table that represents the ID of the object the metadata belongs to.
$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.
$table_aliasesarrayprotected- A flat list of table aliases used in JOIN clauses.
$clausesarrayprotected- A flat list of clauses, keyed by clause 'name'.
$has_or_relationboolprotected- Whether the query contains any OR relations.
Methods · 12
- __construct()Constructor.
- sanitize_query()Ensures the 'meta_query' argument passed to the class constructor is well-formed.
- is_first_order_clause()Determines whether a query clause is first-order.
- parse_query_vars()Constructs a meta query based on 'meta_*' query vars
- get_cast_for_type()Returns the appropriate alias for the given meta type if applicable.
- 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.
- get_clauses()Gets a flattened list of sanitized meta clauses.
- find_compatible_table_alias()Identifies an existing table alias that is compatible with the current query clause.
- has_or_relation()Checks whether the current query has any OR relations.
Source code
#[AllowDynamicProperties]class WP_Meta_Query { /** * Array of metadata queries. * * See WP_Meta_Query::__construct() for information on meta query arguments. * * @since 3.2.0 * @var array */ public $queries = array(); /** * The relation between the queries. Can be one of 'AND' or 'OR'. * * @since 3.2.0 * @var string */ public $relation; /** * Database table to query for the metadata. * * @since 4.1.0 * @var string */ public $meta_table; /** * Column in meta_table that represents the ID of the object the metadata belongs to. * * @since 4.1.0 * @var string */ public $meta_id_column; /** * 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; /** * A flat list of table aliases used in JOIN clauses. * * @since 4.1.0 * @var array */ protected $table_aliases = array(); /** * A flat list of clauses, keyed by clause 'name'. * * @since 4.2.0 * @var array */ protected $clauses = array(); /** * Whether the query contains any OR relations. * * @since 4.3.0 * @var bool */ protected $has_or_relation = false; /** * Constructor. * * @since 3.2.0Changelog
Introduced in 3.2.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 6.8.8 tag, from
src/wp-includes/class-wp-meta-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.