[ Index ]

PHP Cross Reference of WordPress




/wp-includes/ -> class-wp-meta-query.php (summary)

Meta API: WP_Meta_Query class

File Size: 883 lines (30 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Meta_Query:: (12 methods):

Class: WP_Meta_Query  - X-Ref

Core class used to implement meta queries for the Meta API.

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.

__construct( $meta_query = false )   X-Ref

param: array $meta_query {
since: 3.2.0
since: 4.2.0 Introduced support for naming query clauses by associative array keys.
since: 5.1.0 Introduced `$compare_key` clause parameter, which enables LIKE key matches.
since: 5.3.0 Increased the number of operators available to `$compare_key`. Introduced `$type_key`,

sanitize_query( $queries )   X-Ref
Ensure the 'meta_query' argument passed to the class constructor is well-formed.

Eliminates empty items and ensures that a 'relation' is set.

param: array $queries Array of query clauses.
return: array Sanitized array of query clauses.
since: 4.1.0

is_first_order_clause( $query )   X-Ref
Determine whether a query clause is first-order.

A first-order meta query clause is one that has either a 'key' or
a 'value' array key.

param: array $query Meta query arguments.
return: bool Whether the query clause is a first-order clause.
since: 4.1.0

parse_query_vars( $qv )   X-Ref
Constructs a meta query based on 'meta_*' query vars

param: array $qv The query variables
since: 3.2.0

get_cast_for_type( $type = '' )   X-Ref
Return the appropriate alias for the given meta type if applicable.

param: string $type MySQL type to cast meta_value.
return: string MySQL type.
since: 3.7.0

get_sql( $type, $primary_table, $primary_id_column, $context = null )   X-Ref
Generates SQL clauses to be appended to a main query.

param: string $type              Type of meta. Possible values include but are not limited
param: string $primary_table     Database table where the object being filtered is stored (eg wp_users).
param: string $primary_id_column ID column for the filtered object in $primary_table.
param: object $context           Optional. The main query object that corresponds to the type, for
return: string[]|false {
since: 3.2.0

get_sql_clauses()   X-Ref
Generate SQL clauses to be appended to a main query.

Called by the public WP_Meta_Query::get_sql(), this method is abstracted
out to maintain parity with the other Query classes.

return: string[] {
since: 4.1.0

get_sql_for_query( &$query, $depth = 0 )   X-Ref
Generate SQL clauses for a single query array.

If nested subqueries are found, this method recurses the tree to
produce the properly nested SQL.

param: array $query Query to parse (passed by reference).
param: int   $depth Optional. Number of tree levels deep we currently are.
return: string[] {
since: 4.1.0

get_sql_for_clause( &$clause, $parent_query, $clause_key = '' )   X-Ref
Generate SQL JOIN and WHERE clauses for a first-order query clause.

"First-order" means that it's an array with a 'key' or 'value'.

param: array  $clause       Query clause (passed by reference).
param: array  $parent_query Parent query array.
param: string $clause_key   Optional. The array key used to name the clause in the original `$meta_query`
return: string[] {
since: 4.1.0

get_clauses()   X-Ref
Get a flattened list of sanitized meta clauses.

This array should be used for clause lookup, as when the table alias and CAST type must be determined for
a value of 'orderby' corresponding to a meta clause.

return: array Meta clauses.
since: 4.2.0

find_compatible_table_alias( $clause, $parent_query )   X-Ref
Identify an existing table alias that is compatible with the current
query clause.

We avoid unnecessary table joins by allowing each clause to look for
an existing table alias that is compatible with the query that it
needs to perform.

An existing alias is compatible if (a) it is a sibling of `$clause`
(ie, it's under the scope of the same relation), and (b) the combination
of operator and relation between the clauses allows for a shared table join.
In the case of WP_Meta_Query, this only applies to 'IN' clauses that are
connected by the relation 'OR'.

param: array $clause       Query clause.
param: array $parent_query Parent query of $clause.
return: string|false Table alias if found, otherwise false.
since: 4.1.0

has_or_relation()   X-Ref
Checks whether the current query has any OR relations.

In some cases, the presence of an OR relation somewhere in the query will require
the use of a `DISTINCT` or `GROUP BY` keyword in the `SELECT` clause. The current
method can be used in these cases to determine whether such a clause is necessary.

return: bool True if the query contains any `OR` relations, otherwise false.
since: 4.3.0

Generated: Tue May 17 01:00:03 2022 Cross-referenced by PHPXref 0.7.1