get_meta_sql

Given a meta query, generates SQL clauses to be appended to a main query.

Description

(array) get_meta_sql( (array) $meta_query, (string) $type, (string) $primary_table, (string) $primary_id_column, (null) $context = null ); 

Returns (array)

Associative array of `JOIN` and `WHERE` SQL.

Parameters (5)

0. $meta_query (array)
The meta query.
1. $type (string)
Type of meta.
2. $primary_table (string)
Primary database table name.
3. $primary_id_column (string)
Primary ID column name.
4. $context — Optional. (null) => null
The main query object

Usage

  1. if ( !function_exists( 'get_meta_sql' ) ) { 
  2. require_once ABSPATH . WPINC . '/meta.php'; 
  3.  
  4. // The meta query. 
  5. $meta_query = array(); 
  6.  
  7. // Type of meta. 
  8. $type = ''; 
  9.  
  10. // Primary database table name. 
  11. $primary_table = ''; 
  12.  
  13. // Primary ID column name. 
  14. $primary_id_column = ''; 
  15.  
  16. // Optional. The main query object 
  17. $context = null; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = get_meta_sql($meta_query, $type, $primary_table, $primary_id_column, $context); 
  21.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/meta.php  
  1. function get_meta_sql( $meta_query, $type, $primary_table, $primary_id_column, $context = null ) { 
  2. $meta_query_obj = new WP_Meta_Query( $meta_query ); 
  3. return $meta_query_obj->get_sql( $type, $primary_table, $primary_id_column, $context );