get_meta_sql

The timeline below displays how wordpress function get_meta_sql has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Given a meta query, generates SQL clauses to be appended to a main query.
 *
 * @since 3.2.0
 *
 * @see WP_Meta_Query
 *
 * @param array  $meta_query        A meta query.
 * @param string $type              Type of meta.
 * @param string $primary_table     Primary database table name.
 * @param string $primary_id_column Primary ID column name.
 * @param object $context           Optional. The main query object. Default null.
 * @return string[]|false {
 *     Array containing JOIN and WHERE SQL clauses to append to the main query,
 *     or false if no table exists for the requested meta type.
 *
 *     @type string $join  SQL fragment to append to the main JOIN clause.
 *     @type string $where SQL fragment to append to the main WHERE clause.
 * }
 */
function get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context = null)
{
    $meta_query_obj = new WP_Meta_Query($meta_query);
    return $meta_query_obj->get_sql($type, $primary_table, $primary_id_column, $context);
}

WordPress Version: 6.1

/**
 * Given a meta query, generates SQL clauses to be appended to a main query.
 *
 * @since 3.2.0
 *
 * @see WP_Meta_Query
 *
 * @param array  $meta_query        A meta query.
 * @param string $type              Type of meta.
 * @param string $primary_table     Primary database table name.
 * @param string $primary_id_column Primary ID column name.
 * @param object $context           Optional. The main query object
 * @return string[]|false {
 *     Array containing JOIN and WHERE SQL clauses to append to the main query,
 *     or false if no table exists for the requested meta type.
 *
 *     @type string $join  SQL fragment to append to the main JOIN clause.
 *     @type string $where SQL fragment to append to the main WHERE clause.
 * }
 */
function get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context = null)
{
    $meta_query_obj = new WP_Meta_Query($meta_query);
    return $meta_query_obj->get_sql($type, $primary_table, $primary_id_column, $context);
}

WordPress Version: 5.5

/**
 * Given a meta query, generates SQL clauses to be appended to a main query.
 *
 * @since 3.2.0
 *
 * @see WP_Meta_Query
 *
 * @param array  $meta_query        A meta query.
 * @param string $type              Type of meta.
 * @param string $primary_table     Primary database table name.
 * @param string $primary_id_column Primary ID column name.
 * @param object $context           Optional. The main query object
 * @return array Associative array of `JOIN` and `WHERE` SQL.
 */
function get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context = null)
{
    $meta_query_obj = new WP_Meta_Query($meta_query);
    return $meta_query_obj->get_sql($type, $primary_table, $primary_id_column, $context);
}

WordPress Version: 4.1

/**
 * Given a meta query, generates SQL clauses to be appended to a main query.
 *
 * @since 3.2.0
 *
 * @see WP_Meta_Query
 *
 * @param array $meta_query         A meta query.
 * @param string $type              Type of meta.
 * @param string $primary_table     Primary database table name.
 * @param string $primary_id_column Primary ID column name.
 * @param object $context           Optional. The main query object
 * @return array Associative array of `JOIN` and `WHERE` SQL.
 */
function get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context = null)
{
    $meta_query_obj = new WP_Meta_Query($meta_query);
    return $meta_query_obj->get_sql($type, $primary_table, $primary_id_column, $context);
}

WordPress Version: 3.7

/**
 * Given a meta query, generates SQL clauses to be appended to a main query
 *
 * @since 3.2.0
 *
 * @see WP_Meta_Query
 *
 * @param array $meta_query A meta query
 * @param string $type Type of meta
 * @param string $primary_table
 * @param string $primary_id_column
 * @param object $context (optional) The main query object
 * @return array( 'join' => $join_sql, 'where' => $where_sql )
 */
function get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context = null)
{
    $meta_query_obj = new WP_Meta_Query($meta_query);
    return $meta_query_obj->get_sql($type, $primary_table, $primary_id_column, $context);
}